Question
makefile activity: activity.c gcc -o activity activity.c clean: rm -f activity #include #include #include int debug = 0; int main(int argc, char **argv) { extern
makefile
activity: activity.c gcc -o activity activity.c
clean: rm -f activity
#include
int debug = 0;
int main(int argc, char **argv) { extern char *optarg; extern int optind; int c, err = 0; int rflag=0, bflag=0; char *bval = "default_bval", *value; static char usage[] = "usage: %s [-r] -b bval value [value ...] ";
while ((c = getopt(argc, argv, "rb:")) != -1) switch (c) { case 'r': rflag = 1; break; case 'b': bflag = 1; bval = optarg; break; case '?': err = 1; break; } if (bflag == 0) { /* -b was mandatory */ fprintf(stderr, "%s: missing -b option ", argv[0]); fprintf(stderr, usage, argv[0]); exit(1); } else if ((optind+1) > argc) { /* need at least one value */
fprintf(stderr, "%s: missing value ", argv[0]); fprintf(stderr, usage, argv[0]); exit(1); } else if (err) { fprintf(stderr, usage, argv[0]); exit(1); } /* see what we have */ printf("rflag = %d ", rflag); printf("bval = \"%s\" ", bval); if (optind < argc) /* these are the values after the command-line options */ for (; optind < argc; optind++) printf("value: \"%s\" ", argv[optind]); else { printf("no values left to process "); } exit(0); }
whats the output of this
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started