Write C Program Takes Command Line Arguments Prints Original Argument Number Consonants Vo Q43902877
Write a C program that takes command line arguments andprints the original argument with the number of consonants, vowels,and special characters, as well as prints which character makes upthe majority of each argument. Print out the total number ofcharacters of all arguments combined.
Questions:
1. How do I enter multiple exclamation points and have it berecognized as a special character properly? When I input more thanone exclamation point, the compiler thinks there are way morearguments than there are and they aren’t registered as exclamationpoints. For example, when I enter: test!!!!!!.
2. How do I properly implement consonantCheck? The current codedoesn’t print out the correct number of consonants.
3. How do I add the total number of characters of each argumenttogether to get the total number of character of allarguments together? I have the same concern for totalamounts of special characters, consonants, and vowels forcalculations.
Here’s what I have so far:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
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(“nargument %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 formajority 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<strlen(str);i++){
//This only counts the amount of characters of each singleargument, not all
//arguments combined.
characteramount++;
if(specialCheck(str[i])==1){
specialcount++;
}
if(vowelCheck(str[i])==1){
vowelcount++;
}
if(consonantCheck(str[i])==1){
consonantcount++;
}
}
printf(“nNumber of consonants: %d, Number of vowels: %d, Numberof special characters: %dn”, consonantcount, vowelcount,specialcount);
printf(“nThe total number of characters: %dn”,totalcharacteramount);
if(totalvowelcount>(totalcharacteramount/2))
printf(“n The majority character in argument %d is vowels.n”,str[i])
if(totalspecialcount>(totalcharacteramount/2))
printf(“n The majority character in argument %d is specialcharacters.n”, str[i])
if(totalconsonantcount>(totalcharacteramount/2))
printf(“n The majority character in argument %d is consonants.n”,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;
}
Expert Answer
Answer to Write a C program that takes command line arguments and prints the original argument with the number of consonants, vowe…
OR