Question: Write a C program that takes command line arguments and displays the number of consonants, vowels, and special characters. Do not hard code the consonants

Write a C program that takes command line arguments and displays the number of consonants, vowels, and special characters. Do not hard code the consonants and special characters.

1. How do you pass each character of the command line argument to the function printResults?

And how do you get the total amount of characters in every argument WITHOUT using strlen too many times like the following:

void printResults(char *str){

int i;

for (i=0; i

//whatever goes here

}

2. How do you implement strlen in the printResults function?

3. How do you count exclamation marks ( ! ) as a character that can be read and added as a special character?

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; int j = 0;

//nested for loop //go through every argument in command line for (i = 1; i < argc; i ++) { j = 0;

//go through every character until it reaches the end of string while(argv[i][j] != '\0'){ printf("Argument %d letter %d: %c ", i, j, argv[i][j++]);

//passes the every element's address in the string argument printResults(&argv[i][j++]); } } return 0; }

//How do you pass every character from the command line argument to this function?

void printResults(char *str) { int i;

//How do you get the length of each command line argument? int characteramount=strlen(str);

int specialcount=0;

int vowelcount=0;

int consonantcount=0;

for(i=0;i

if(specialCheck==1){

specialcount++;

}

if(vowelCheck==1){

vowelcount++;

}

if(consonantCheck==1){

consonantcount++;

}

}

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

}

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; }

int specialCheck(char ch) { if(isalpha(c)){ return 1;

} else{ 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;

//or:

if(isalpha(ch)){

if(vowelcheck(ch)==0){

return 1;

}

}

}

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!