title: Scan a file to search pre-defined c keywords and print them on console
body: <p>How can I scan a file for a word and then print the line containing that word in C programming?</p>
  
  <p>I am trying to find a way to scan a file for a keyword and then print only the line containing that word. I am off to a very rough start. Here is what I have:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void getDsk (void);
  
  void getDsk ()
  {
  FILE* fp;
  char result [1000];
  fp = popen("diskutil list","r");
  fread(result,1,sizeof(result),fp);
  fclose (fp);
  
  while(!feof(fp)) {
          if(//line contains "Test".)
          {
              //show line.
          }
      }
  }
  
  int main(int argc, const char * argv[])
  {
      getDsk();
      return 0;
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> This did what I needed.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void getDsk (void);
  
  void getDsk ()
  {
      printf("Your available Windows installations are:\n");
      FILE* fp = popen("diskutil list","r");
      char line[1024];
      while(fgets(line, sizeof(line), fp)) 
      {
          if (strstr(line,"Microsoft")) 
          {
              printf("%s", line);
          }
          // if line contains the text, print it
      }
  }
  
  int main(int argc, const char * argv[])
  {
      getDsk();
      return 0;
  }
  </code></pre>