If it does not seem to be reading the file over the second time, you will have to rewind it to the beginning each iteration of the while(!flag) loop.
Code:
while (!flag)
{
rewind(record_file);
while (fread(&tmp,sizeof(record_structure),1,record_file)) {
if (strcmp(searchtitle,tmp.Title) == 0){
printf("\n\n\nTitle: %s \t\tAuthor: %s \t\tISBN: %s\n", tmp.Title, tmp.Author, tmp.ISBN);
flag = 1;
break;
}
printf("\nThe title you entered does not exist please re-enter: ");
scanf("%[^\n]%*c", searchtitle);
}
}
fclose(record_file);
Try that, and see if it works.
OOPS: Sorry I made a mistake. You do need that second if, because otherwise if will ask you to enter a new search title regardless of whether it found one already: here is the correction:
Code:
while (!flag)
{
rewind(record_file);
while (fread(&tmp,sizeof(record_structure),1,record_file)) {
if (strcmp(searchtitle,tmp.Title) == 0){
printf("\n\n\nTitle: %s \t\tAuthor: %s \t\tISBN: %s\n", tmp.Title, tmp.Author, tmp.ISBN);
flag = 1;
break;
}
}
if(!flag)
{
printf("\nThe title you entered does not exist please re-enter: ");
scanf("%[^\n]%*c", searchtitle);
}
}
fclose(record_file);