16 command Line Arguments -parse command line function This program has the same
ID: 3811467 • Letter: 1
Question
16 command Line Arguments -parse command line function This program has the same behavior and produces the same output as problem 1 above. Instead of processing the command line arguments in main, you will write a read the function named parse command line. The parse command line function will command line arguments, convert the argv11l string to an integer for rows, and convert the argv12) value to an integer value the parse command for columns. Note that line function will return two values: rows, columns. The parse command line function prototype must be written as follows: void parse command line( int argc, char argvn.int rows, int cols); Example: illustrate parse command line function The parse command line function will read the command line arguments, convert the argvl1] string to an integer value for rows, and convert the argv[2] value to an integer value for columns. Note that the parse command line function will return two values: rows, columns. Ainclude printf #include atoi void parse command line( int argc, char argv0 int rows, int cols) int main (int argc, char 'argv0) int rows, cols; program requires a minimum of 3 command line arguments argc must be at least 3 argvlo] executable name argvl1] input rows value argv12] input cols valueExplanation / Answer
#include<stdio.h>
void main(int argc ,char* argv[]) {
void parse_command_line(int, char **, int*, int*);
int rows, cols;
if (argc < 3) {
printf("program terminating. Too few arguments ");
printf("should be in format program name row column ");
return;
}
parse_command_line(argc, argv, &rows, &cols);
printf(" rows:%d , cols: %d ",rows,cols);
}
void parse_command_line(int argc, char* argv[], int* row, int *col) {
*row = atoi(argv[1]);
*col = atoi(argv[2]);
}
I hope you like the code! Let me know if you have any doubts.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.