title: Count words in a file?
body: <p>I have a program written in C which should count the number of times the word "the" appears in text files that are given as arguments.But the program keeps giving a segmentation fault error and I have no more ideas on how to solve this.Any help would be appreciated.Thank you!</p>
  
  <p>Here is the code:</p>
  
  <pre>
  <code>
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  void main(int argc, char *argv[])
  { 
    int h,i;
    FILE *fp;
    char* mess;
    for(i=1; i &lt; argc; i++)
    { 
       h=0;
       fp=fopen(argv[i],"r");
        while (!feof(fp))
        { 
          fscanf(fp,"%s",mess);
          if (strcmp(mess,"the")==0)
            h++;
        }
        printf("The file %s contains the word \"the\" %d times.",argv[i],h);
        h=0; 
        fclose(fp);
    }
  }
  </code>
  </pre>