Code:#include <stdio.h> #include <ctype.h> int main() { FILE *fptr; char cha, vowel[11] = {"AEIOUaeiou"}; int i, j, n_char = 0, n_let = 0, n_vow = 0, n_con = 0, letter[26] = {0}; for (i=0; i<26; i++) { letter[i] += 65 + i; } fptr = fopen("text.txt","r"); while ( !feof(fptr) ) { fscanf(fptr,"%c",&cha); printf("%c", cha); n_char++; for (i=0; i<26; i++) { if ( cha == (char)letter[i] || cha == tolower( (char)letter[i]) ) { n_let++; for (j=0; j<10; j++) { if ( cha == vowel[j] ) n_vow++; } } } if ( !(cha == 'a' ||cha == 'e'|| cha == 'i'|| cha == 'o'||cha == 'u') ) n_con++; } printf("\nTotal number of characters: %d\n", n_char); printf("Number of letters: %d\n", n_let); printf("Number of vowels: %d\n", n_vow); printf("Number of consonants: %d\n", n_con); }
How to avoid the repetition of last character?