I have a code in which I am getting warning of unchecked return value-
bool check() {
FILE* fptr = fopen(fi.txt, "r");
if(fptr != NULL) {
while(!feof(fptr)) {
fscanf(fptr, "%s", var1);
if(strcmp(fptr, var2) == 0) {
fclose(fptr);
return true;
}
}
fclose(fptr);
}
return false;
}
I have found a way to rewrite this code as I am getting warning like this
Calling fscanf(fptr, "%s", var1) without checking return value. This library function may fail and return an error code.
Here is another way, is this thr right way or not-
if(fptr != NULL) {
while(fscanf(fptr, "%s", var1) == 0) {
if(strcmp(var1, var2) == 0) {
fclose(fptr);
return true;
}
fclose(fptr);
}
return false;
}