Question: In C programming! Write a program that prompts a user to input a sequence of characters (including spaces and special characters) and then uses your

In C programming!

Write a program that prompts a user to input a sequence of characters (including spaces and special characters) and then uses your (user defined) functions to output:

  • the number of characters in the string
  • the number of vowels in the string
  • the number of UPPERCASE letters in the string
  • the number of lowercase letters in the string
  • the number of other characters in the string

Your program will need the following 4 functions (use these exact function names):

  • boolean function, IsVowel, that takes a char and returns a true if a given character is a vowel, otherwise returns false
  • int function, CountUC, that takes a string and returns the number of UPPERCASE letters in the string
  • int function, CountLC, that takes a string and returns the number of lowercase letters in the string
  • int function, CountOthers, that takes a string and returns the number of non-letters in the string

RESTRICTIONS: Your program MAY NOT use any predefined function from . You must define and call your own functions.

NOTES: Be sure to include your function prototypes before your main function, and your function definitions after your main function.

Sample output (sample input shown with italics):

Enter a sentence: Is THIS another Test???

There are 23 total characters.

There are 6 vowels.

There are 6 UPPERCASE letters.

There are 11 lowercase letters.

There are 6 other characters.

_____________________________________

Here is the code I have so far:

#include #include

bool isVowel(char ch) { return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'; }

int countUC(char *str) { int count = 0, i = 0; char ch; while((ch = str[i++])) { if(ch >= 'A' && ch <= 'Z') { ++count; } } return count; }

int countLC(char *str) { int count = 0, i = 0; char ch; while((ch = str[i++])) { if(ch >= 'a' && ch <= 'z') { ++count; } } return count; }

int countOthers(char *str) { int count = 0, i = 0; char ch; while((ch = str[i++])) { if(!((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))) { ++count; } } return count; }

int countVowels(char *str) { int count = 0, i = 0; char ch; while((ch = str[i++])) { if(isVowel(ch)) { ++count; } } return count; }

int countCharacters(char *str) { int count = 0; while(str[count++]); return count-1; }

int main() { char str[100]; printf("Enter a sentence: "); scanf("%s", str); printf("There are %d total characters. ", countCharacters(str)); printf("There are %d vowels. ", countVowels(str)); printf("There are %d UPPERCASE letters. ", countUC(str)); printf("There are %d lowercase letters. ", countLC(str)); printf("There are %d other characters. ", countOthers(str)); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!