Question

In: Computer Science

Modify program so that input comes in as command line arguments. Sample run: ./a.out W8 4...

Modify program so that input comes in as command line arguments.
Sample run:
./a.out W8 4 ME 2 finish 2!
Output:
Consonants: WMfnsh


1) Name your program command_consonants.c.

2) If no command line arguments was provided, your program should print a usage message “Usage: ./a.out input

#include<stdio.h>

int main()
{
printf("Input: ");
int i = 0;
char ch;
// array to store consonants
char consonant[100]={""};
//do loop to take input
do
{
ch = getchar();
//checks to see if consonants or not
if(((ch >= 'a' && ch <= 'z')||(ch >= 'A' && ch <= 'Z')) && !(ch == 'a' || ch == 'e' || ch == 'i'|| ch == '0' || ch == 'u' || ch == 'A' || ch =='E'|| ch=='I' || ch =='O' || ch == 'U'))
{
consonant[i] = ch;
i++;
}
  
}
while(ch != '\n');
  
printf("Consonants:");
printf("%s", consonant);
  
return 0;
}

Solutions

Expert Solution

CODE -

#include<stdio.h>

int main(int argc, char* argv[])

{

    int i = 0;

    char ch;

    // array to store consonants

    char consonant[100]={""};

    // Printing usage message if no command line arguments was provided.

    if(argc==1)

        printf("Usage: ./a.out input");

    // Iterating over each space seperated string in the command line input

    for(int j=1; j<argc; j++)

    {

        int k=0;

        // do loop to read character by character of the strings in command line input

        do

        {

            ch = argv[j][k];

            //checks to see if consonants or not

            if(((ch >= 'a' && ch <= 'z')||(ch >= 'A' && ch <= 'Z')) && !(ch == 'a' || ch == 'e' || ch == 'i'|| ch == '0' || ch == 'u' || ch == 'A' || ch =='E'|| ch=='I' || ch =='O' || ch == 'U'))

            {

                consonant[i] = ch;

                i++;

            }

            k++;

        }while(ch != '\0');

    }

    

    printf("Consonants: ");

    printf("%s", consonant);

    

    return 0;

}

SCREENSHOT -

If you have any doubt regarding the solution, then do comment.
Do upvote.


Related Solutions

IN C LANGUAGE This program takes two command line arguments: an input filename a threshold Your...
IN C LANGUAGE This program takes two command line arguments: an input filename a threshold Your program will create two files: even.txt - contains all integers from the input file that are even and greater than the threshold odd.txt - contains all integers from the input file that are odd and greater than the threshold The input file will exist and only contain a set of integers. It will always be valid data. Output whitespace will be ignored. Name the...
Write a program that takes two command line arguments at the time the program is executed....
Write a program that takes two command line arguments at the time the program is executed. You may assume the user enters only decimal numeric characters. The input must be fully qualified, and the user should be notified of any value out of range for a 23-bit unsigned integer. The first argument is to be considered a data field. This data field is to be is operated upon by a mask defined by the second argument. The program should display...
Modify this program so that it takes in input from a TEXT FILE and outputs the...
Modify this program so that it takes in input from a TEXT FILE and outputs the results in a seperate OUTPUT FILE. (C programming)! Program works just need to modify it to take in input from a text file and output the results in an output file. ________________________________________________________________________________________________ #include <stdio.h> #include <string.h> // Maximum string size #define MAX_SIZE 1000 int countOccurrences(char * str, char * toSearch); int main() { char str[MAX_SIZE]; char toSearch[MAX_SIZE]; char ch; int count,len,a[26]={0},p[MAX_SIZE]={0},temp; int i,j; //Take...
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For...
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For example, java Adder 3 2.5 -4.1 should print The sum is 1.4
Write a C++ program that prints out all of the command line arguments passed to the...
Write a C++ program that prints out all of the command line arguments passed to the program. Each command line argument should be separated from the others with a comma and a space. If a command line argument ends in a comma, then another comma should NOT be added
program c Write a program called filesearch that accepts two command-line arguments: A string A filename...
program c Write a program called filesearch that accepts two command-line arguments: A string A filename If the user did not supply both arguments, the program should display an error message and exit. The program opens the given filename. Each line that contains the given string is displayed. Use the strstr function to search each line for the string. You may assume no line is longer than 255 characters. The matching lines are displayed to standard output (normally the screen).
16.15 Lab 5: filter Name this program filter.c. The program takes two command line arguments: the...
16.15 Lab 5: filter Name this program filter.c. The program takes two command line arguments: the name of an input file and the name of an output file. The program should confirm the input and output files can be opened. If a file cannot be opened, print the error message Cannot open file '<filename>' where <filename> is the name of the file and return. fopen() will return 0 if it fails to open a file. Then, the program will read...
Modify the program so that after it reads the line typed on the keyboard, it replaces...
Modify the program so that after it reads the line typed on the keyboard, it replaces the ‘\n’ character with a NUL character. Now you have stored the input as a C-style string, and you can echo it with: Explain what you did. #include <unistd.h> #include <string.h> int main(void) { char aString[200]; char *stringPtr = aString; write(STDOUT_FILENO, "Enter a text string: ", strlen("Enter a text string: ")); // prompt user read(STDIN_FILENO, stringPtr, 1); // get first character while (*stringPtr !=...
Write a program Median.java to read each file whose name is specified in the command-line arguments....
Write a program Median.java to read each file whose name is specified in the command-line arguments. That is, for each command-line argument, open it as a file and read it. The file contents are zero or more lines each containing a list of comma-separated integers, such as 1,2,3,4 or 99,120,33. You should parse each of these integers and save them in an ArrayList (if you prefer you may use an array, but an ArrayList is likely to be easier for...
"4. (Modify) Modify Program 7.14 so that the user inputs the initial set of numbers when...
"4. (Modify) Modify Program 7.14 so that the user inputs the initial set of numbers when the program runs. Have the program request the number of initial numbers to be entered." //C++ Program 7.14 as follows #include #include #include #include using namespace std; int main() { const int NUMELS = 4; int n[] = {136, 122, 109, 146}; int i; vector partnums(n, n + NUMELS); cout << "\nThe vector initially has the size of " << int(partnums.size()) << ",\n and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT