title: c program to read file and count words specified in array
body: <p>I'm trying to read a file containing a paragraph, count the number of times specific words occur (words that I have specified and stored in an array) and then print that result to another file that would look something like,</p>
  <pre><code>systems, 2
  computer, 3
  programming, 6
  </code></pre>
  <p>and so on. Currently, all this code does is spit out every word in the paragraph and their respective counts. Any help would be much appreciated.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int main()
  {
      FILE* in;
      FILE* out;
  
      char arr1[13][100] = { &quot;systems&quot;, &quot;programming&quot;, &quot;computer&quot;, &quot;applications&quot;, &quot;language&quot;, &quot;machine&quot;};
      int arr2[180] = {0};
      int count = 0;
      char temp[150];
  
      in = fopen(&quot;out2.dat&quot;, &quot;r&quot;);
      out = fopen(&quot;out3.dat&quot;, &quot;w&quot;);
  
      while (fscanf(in, &quot;%s&quot;, temp) != EOF)
      {
          int i, check = 8;
          for (i = 0;i &lt; count;i++)
          {
              if (strcmp(temp, arr1[i]) == 0)
              {
                  arr2[i]++;
                  check = 1;
                  break;
              }
          }
          if (check == 1) continue;
          strcpy(arr1[count], temp);
          arr2[count++] = 1;
      }
      int i;
      for (i = 0; i &lt; count; i++)
          fprintf(out, &quot;%s, %d\n&quot;, arr1[i], arr2[i]);
  
      return 0;
  }
  </code></pre>