C Programming Code Examples C > Strings Code Examples program to count the number of vowels, consonants and so on program to count the number of vowels, consonants and so on This program takes string input from the user and stores in variable line. Initially, the variables vowels, consonants, digits and spaces are initialized to 0. When the vowel character is found, vowel variable is incremented by 1. Similarly, consonants, digits and spaces are incremented when these characters are found. Finally, the count is displayed on the screen. #include <stdio.h> int main() { char line[200]; int j, vowels, consonants, digits, spaces; vowels = consonants = digits = spaces = 0; printf("Enter a line of string: "); scanf("%[^\n]", line); for(j=0; line[j]!='\0'; ++j) { if(line[j]=='a' || line[j]=='e' || line[j]=='i' || line[j]=='o' || line[j]=='u' || line[j]=='A' || line[j]=='E' || line[j]=='I' || line[j]=='O' || line[j]=='U') { ++vowels; } else if((line[j]>='a'&& line[j]<='z') || (line[j]>='A'&& line[j]<='Z')) { ++consonants; } else if(line[j]>='0' && line[j]<='9') { ++digits; } else if (line[j]==' ') { ++spaces; } } printf("Vowels: %d",vowels); printf("\nConsonants: %d",consonants); printf("\nDigits: %d",digits); printf("\nWhite spaces: %d", spaces); return 0; }