pangfengliu / programmingtasks

programming tasks from my courses
68 stars 17 forks source link

Vowel, Consonant, and Digit #24

Open pangfengliu opened 10 years ago

pangfengliu commented 10 years ago

Task Description

Write a program that counts the number of digits, letters, vowels, and consonants in a string s.

Limits

The length of string s is no more than 100.

Input Format

There is one line in the input. The first line has the string s.

Output Format

There is one line in the output. The first line has the four numbers as in the description.

Sample Input

string_123

Sample Output

3 6 1 5

Tatopus commented 4 years ago

include

include

include

int check(char c[], int num, int let,int vow, int con) { num = let = vow = con =0; for(int i =0 ; i< strlen(c); i++) { c[i] = toupper(c[i]); printf("c[%d] is : %c\n",i,c[i]); if(isdigit(c[i])) { num +=1; } if(isalpha(c[i])) { let +=1; switch(c[i]) { case 'A' : case 'E' : case 'I' : case 'O' : case 'U' : vow +=1; break; default : con +=1; break; } }

}   

}

int main(void) { char s[100] ; int num, let, vow, con; scanf("%s", s); check(s,&num,&let,&vow,&con); printf("%d %d %d %d",num,let,vow,con); }