C Programming: Use Code: :Blocks to write a program to solve this problem: 5. Vo
ID: 3679319 • Letter: C
Question
C Programming: Use Code: :Blocks to write a program to solve this problem:
5. Vowels.
Prompt the user to enter a sentence, then hit newline. Read the sentence one character at a time, until you come to the newline character. Count the total number of keystrokes entered, the number of alphabetic characters, and the number of vowels ('a', 'e', 'i', 'o', and 'u'). Output these three counts.
Note: Vowels (a,e,i,o,u) can be in upper or lower case to count.
You can have unlimited number of sentences, the last sentence has nothing in it but a "return" character in it. When this empty sentence is entered, you end the program. Keystrokes counter does NOT include the enter/return key. You must use the library routines in ctype.h and the SWITCH statement and the toupper or tolower and ISALPHA functions. Output will be for EACH sentence.
SAMPLE INPUT:
This is a Number 1 SAMPLE INPUT SentANce out of 1.
Sample Sentence#2
Sample Sentence#3
...
empty sentence denoted by nothing but 'return' key
SAMPLE OUTPUT, for EACH sentence above:
Problem#5 CSCI1110
Keystrokes: 9999
Alpha Characters: 9999
Vowels: 9999
----PARTIAL SAMPLE OUTPUT:
Keystrokes: 50
Alpha Characters: 37
Vowels: 15
Explanation / Answer
#include<stdio.h>
#include<ctype.h>
int isVowel(char c){
char ch = tolower(c);
switch(ch){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
return 1;
}
return 0;
}
int ISALPHA(char c){
if(isalpha(c))
return 1;
return 0;
}
int main(){
char word[256] = {''};
printf("Enter sentences.. empty to stop ");
while(fgets(word, sizeof(word), stdin)) {
// return key check
if(word[0]==' ' || word[0] =='')
break;
int i=0;
int keyStroke = 0;
int alpha = 0;
int vowel = 0;
while(word[i] != ''){
keyStroke++;
if(ISALPHA(word[i])){
alpha++;
if(isVowel(word[i]))
vowel++;
}
i++;
}
printf("Keystrokes: %d ",keyStroke);
printf("Alpha Characters: %d ",alpha);
printf("Vowels: %d ",vowel);
printf("Enter sentences.. empty to stop ");
}
return 0;
}
/*
Output:
Enter sentences.. empty to stop
Pravesh Kumar
Keystrokes: 14
Alpha Characters: 12
Vowels: 4
Enter sentences.. empty to stop
adsfwqefhewkd dd2wedwqeyikqejnd w kd2
Keystrokes: 38
Alpha Characters: 32
Vowels: 7
Enter sentences.. empty to stop
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.