OnesQuared OnesQuared - 12 days ago 6
C Question

using constant filepointer to rewind and fscanf

I am trying to use a const FILE *fp to rewind, fscanf and etc. the usual stuff but I run into c4090 error and I am not quite understanding it.

int search(const FILE *fp, int patt) {
if (fp != NULL) {
rewind(fp) //Getting c4090 warning
//other statements
}
}


This seems like a basic question and I tried searching for a bit and microsoft manual is mostly what I've got and I don't really understand what they are implying

Answer

"This warning can be caused when a pointer to a const or volatile item is assigned to a pointer not declared as pointing to const or volatile."

Source: https://msdn.microsoft.com/en-us/library/k77bkb8d.aspx

Try:

int search(FILE *fp, int patt) {
    if (fp != NULL) {
     rewind(fp) //No c4090 warning, Because we can change fp
     //other statements
    }
}
Comments