Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

write your code to allow users to use command-line arguments to specify number X to be printed Y times. Make sure your check possible wrong

write your code to allow users to use command-line arguments to specify number X to be printed Y times. Make sure your check possible wrong inputs of X and Y (including X not as a number or Y as negative or non-integer). Your source code can be written either inside Ubuntu using vi, pico, nano, etc. or in your host system then shared to Ubuntu. Run your program with different (correct and incorrect) inputs and show that your code works as needed and take snapshots of these.

Change the code so that users can specify an integer X to be printed out Y times on screen. So the command should be

./ch1 X Y

and the result

X

X

X

Make sure you check possible wrong inputs in X and Y.

#include

#include

#include

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

{

int max_num;

//check number of arguments. This number includes the command

if (argc != 2) {

printf("Usage: %s max_num (must be an integer) ", argv[0]);

return 1;

}

//convert argument string to integer

max_num = atoi(argv[1]);

for(int i = 0; i < counter; i++){

//counter is what Y was in the example.

printf("X");

}

printf("max_num=%d ", max_num);

return 0;

}

So I cannot figureout what wrong with this code.

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_2

Step: 3

blur-text-image_3

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

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students explore these related Databases questions