title: c programming search file for string
body: <p>so I have to write a function that reads from a file and scans it to see if any of the titles within it matches the title that the user puts in and prints all of the existing titles in the format title: (title)    Author:(last name, first name). if no titles match then it prints no titles found. I can get the program to read in the titles into an array and also print in the format that i want, but my problem is searching the file to find matching titles to print them.. The program just prints off no titles match 5 times even when there is a match..any help would be greatly appreciated...Thank you...</p>
  
  <pre><code>void findBookByTitle(FILE* fp, char title[])
  {
  FILE* open = fp;
  char title2[200];
  char last[200];
  char first[200];
  int i=0;
  
  while(!feof(fp))
  {
  fscanf(fp, "%[^;];%[^;];%[^\n]", title2, last, first);
  if( strcmp(title2,title)==0)
  {
  printf("Title: %s\n", title2);
  printf("Author: %s,%s\n", last,first);
  }
  else {
     printf("No books match the title: %s\n", title);
   }
  
  }
  }
  </code></pre>
  
  <p>The text files say:</p>
  
  <pre><code>Making The Right Choices; Henry; Mark
  Time For Change; Robinson; Chris
  Battle For Air; Jetson; Lola
  The Right Moves; Henry;Mark
  People Today; Robinson; Chris                                             
  </code></pre>
  
  <p>So if the user wants to search for book Time to change it would print out author: time for change
  Author: Henry, Mark
  But my function just prints off no books match over and over....</p>