Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program that takes command line arguments and prints the original argument with the number of consonants, vowels, and special characters, as well

Write a C program that takes command line arguments and prints the original argument with the number of consonants, vowels, and special characters, as well as prints which character makes up the majority of each argument. Print out the total number of characters of all arguments combined.

Questions:

1. How do I enter multiple exclamation points and have it be recognized as a special character properly? When I input more than one exclamation point, the compiler thinks there are way more arguments than there are and they aren't registered as exclamation points. For example, when I enter: test!!!!!!.

2. How do I properly implement consonantCheck? The current code doesn't print out the correct number of consonants.

3. How do I add the total number of characters of each argument together to get the total number of character of all arguments together? I have the same concern for total amounts of special characters, consonants, and vowels for calculations.

Here's what I have so far:

#include #include #include

void printResults(char *str); int vowelCheck(char ch); int specialCheck(char ch); int consonantCheck(char ch);

int main(int argc, char **argv){ int i = 0; //go through every argument in command line for (i = 1; i < argc; i ++) { printf(" argument %d : %s", i, argv[i]);

//This passes a pointer to the argument to printResults printResults(argv[i]); } return 0; }

//This checks the characters of the string void printResults(char *str) { int i;

int characteramount=0;

//Trying to get the total amounts of all arguments combined for majority calculations int totalcharacteramount=0; int totalspecialcount=0; int totalvowelcount=0; int totalconsonantcount=0;

int specialcount=0;

int vowelcount=0;

int consonantcount=0;

//This only goes through each individual argument for(i=0;i

if(specialCheck(str[i])==1){

specialcount++;

}

if(vowelCheck(str[i])==1){

vowelcount++;

}

if(consonantCheck(str[i])==1){

consonantcount++;

}

}

printf(" Number of consonants: %d, Number of vowels: %d, Number of special characters: %d ", consonantcount, vowelcount, specialcount); printf(" The total number of characters: %d ", totalcharacteramount);

if(totalvowelcount>(totalcharacteramount/2)) printf(" The majority character in argument %d is vowels. ", str[i])

if(totalspecialcount>(totalcharacteramount/2)) printf(" The majority character in argument %d is special characters. ", str[i])

if(totalconsonantcount>(totalcharacteramount/2)) printf(" The majority character in argument %d is consonants. ", str[i])

}

int vowelCheck(char ch) {

if (ch == 'i' || ch == 'a' || ch == 'o' || ch == 'e' || ch == 'u' || ch == 'I' || ch == 'A' || ch == 'E' || ch == 'U' || ch == 'O') return 1;

return 0; }

int specialCheck(char ch) { if(!isalpha(ch) && !isdigit(ch)){ return 1;

} return 0; }

int consonantCheck(char ch) { if (ch != 'i'&& ch != 'a' && ch != 'o' && ch != 'e' && ch != 'u' && ch != 'I' && ch != 'A' && ch != 'E' && ch != 'U'&& ch != 'O')

return 1;

//I also tried the following, but it still doesn't workingif (isalpha(c)){ if(isVowel(c)==0){ return 1; } }

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

List behaviors to improve effective leadership in meetings

Answered: 1 week ago