title: C Beginner: How to search for particular words in a file (line by line) in C
body: <p>I need to search for two particular words in a file line by line and if they exist, print "Found!".</p>
  
  <p>This is file.txt (has four columns)</p>
  
  <pre><code>bill gates 62bill microsoft 
  beyonce knowles 300mill entertainment 
  my name -$9000 student
  </code></pre>
  
  <p>The following is the idea I had but it doesn't seem to work</p>
  
  <pre><code>char firstname[];
  char lastname[];
  char string_0[256];
  
  file = fopen("file.txt","r+");
  
  while((fgets(string_0,256,file)) != NULL) {
  
    //scans the line then sets 1st and 2nd word to those variables
    fscanf(file,"%s %s",&amp;firstname, &amp;lastname);
  
    if(strcmp(firstname,"beyonce")==0 &amp;&amp; strcmp(lastname,"knowles")==0){
      printf("A match has been found");
    }
  }
  
  fclose(file);
  </code></pre>
  
  <p>Please help. Could it be that the pointer is not moving to the next line in the while loop? And if so, how can i fix?</p>