Quote Originally Posted by ronin View Post
Code:
short found = 0;

while(found == 0 && fread(...) == 1)
{
   if(strcmp(...))
   {
       ... /print your record
       found = 1;
   }
}

if(found == 0)
   printf("no records found");
What if there are multiple records matching the search query? How about this

Code:
bool found=false;
while (fread(...) == 1) {
   if (strcmp(...) == 0) {
      // ...
      found = true;
   }
}
if (!feof(fp)) {
   fprintf(stderr, "Error in reading file!\n");
   exit(EXIT_FAILURE);
}
if (!found) {
   printf("No records found!\n");
}