This is what I have come up with so far.
#include<stdio.h>
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);
}
--END OF CODE--
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"