title: How to count the number of words from a text file in C
body: <p>This is what I have come up with so far.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  main()
  {
  int w=0, v=0, c=0, cnt=0;
  char inp[21]="abcd aeiou hi there", ch;
  FILE *read, *write;
  
  write = fopen("D:/wordvowelcharacter.txt", "w");
  fprintf(write, "%s", inp);
  
  fclose(write);
  
  read = fopen("D:/wordvowelcharacter.txt", "r");
  
  if (read==NULL)
  {
      printf("Error opening file");
  }
  
  while ((ch=fgetc(read))!=EOF)
  {
      if (ch!=' ')
      {
          c++;
      }
  
      if          (ch=='A'||ch=='a'||ch=='E'||ch=='e'||ch=='I'||ch=='i'||ch=='O'||ch=='o'||ch=='U'||ch=='u')
      {
          v++;
      }
  
      if (ch==' ')
      {
          w++;
      }
  
  }
  printf("Character %d Vowel %d Word %d", c, v, w);
  
  }
  </code></pre>
  
  <p>--END OF CODE--</p>
  
  <p>The last if statement is of incrementing the word count. What condition should I put there?The current condition gives me wrong number of words, i.e, number of spaces only.
  The text in the file is :
  "abcd aeiou hi there"</p>