#include /* Count the number of vowels, and the number of consonants in a file. */ int main() { FILE *inputFile ; int consonantCount, vowelCount ; char ch ; inputFile = fopen("yourFile.txt", "r") ; consonantCount = 0 ; vowelCount = 0 ; /* For each character in the file in turn, test if it is a consonant or vowel, and if so, adjust total accordingly. */ while ( fscanf(inputFile, "%c", &ch) != EOF ) { if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U') { /* Vowel. */ vowelCount++ ; } else if ( (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ) { /* Consonant, since vowels already dealt with. */ consonantCount++ ; } } printf("\nFile has %d consonants and %d vowels.\n", consonantCount, vowelCount) ; fclose(inputFile) ; return 0; }