Menu

Write C Program Takes Command Line Arguments Displays Number Consonants Vowels Special Cha Q43898392

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

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

And how do you get the total amount of characters in everyargument WITHOUT using strlen too many times likethe following:

void printResults(char *str){

int i;

for (i=0; i<strlen(str); i++)

       //whatever goeshere

}

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

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

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

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

      //go through every characteruntil it reaches the end of string
      while(argv[i][j] != ‘ ‘){
        printf(“Argument %dletter %d: %cn”, i, j, argv[i][j++]);

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

//How do you pass every character from the command line argumentto 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<strlen(str);i++){

      if(specialCheck==1){

         specialcount++;

         }

     if(vowelCheck==1){

         vowelcount++;

         }

    if(consonantCheck==1){

         consonantcount++;

         }

}

printf(“Number of consonants: %d, Number of vowels: %d, Numberof 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’)
          return1;
}

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’)
         
          return1;

//or:

if(isalpha(ch)){

   if(vowelcheck(ch)==0){

        return 1;

     }

}

}

Expert Answer


Answer to Write a C program that takes command line arguments and displays the number of consonants, vowels, and special character…

OR