title: Search for string in text file C
body: <p>The following code reads a text file one character at the time and print it to stdout:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      char file_to_open[] = "text_file.txt", ch;
      FILE *file_ptr;
  
      if((file_ptr = fopen(file_to_open, "r")) != NULL)
      {
          while((ch = fgetc(file_ptr)) != EOF)
          {
              putchar(ch);
          }
      }
      else
      {
          printf("Could not open %s\n", file_to_open);
          return 1;
      }
      return(0);
  }
  </code></pre>
  
  <p>But instead of printing to stdout [putchar(ch)] I want to search the file for specific strings provided in another textfile ie. strings.txt and output the line with the match to out.txt</p>
  
  <p><code>text_file.txt</code>:</p>
  
  <pre>
  1993 - 1999 Pentium
  1997 - 1999 Pentium II
  1999 - 2003 Pentium III
  1998 - 2009 Xeon
  2006 - 2009 Intel Core 2
  </pre>
  
  <p><code>strings.txt</code>:</p>
  
  <pre>
  Nehalem
  AMD Athlon
  Pentium
  </pre>
  
  <p>In this case the three first lines of <code>text_file.txt</code> would match. I have done some research on file operations in C, and it seems that I can read one character at the time with <code>fgetc</code> [like I do in my code], one line with <code>fgets</code> and one block with <code>fread</code>, but no word as I guess would be perfect in my situation?</p>