subject

Use sample program from called getopt. c (provided below) Make a copy of getopt. c and call it gactivity. c
Create a Makefile to compile the activity program.
Modify gactivity. c for the following usage:
Usage: gactivity [-b] -c cname -d data value1 value2 [value ...]
Where the -b option is optional
The -c option is required and needs an argument to go with it.
The -d option is required and needs an argument to go with it.
At least two value are included but there may be more than two.
The program should print out all the flags and values at the end so it should be modified throughout to match the new usage.
Program should print error if invalid options are used or missing options or parameters.
getopt. c
/*
example of command line parsing via getopt
usage: getopt [-dmp] -f fname [-s sname] name [name ...]
Paul Krzyzanowski
*/
#include
#include
int debug = 0;
int
main(int argc, char **argv)
{
extern char *optarg;
extern int optind;
int c, err = 0;
int mflag=0, pflag=0, fflag = 0, sflag=0;
char *sname = "default_sname", *fname;
static char usage[] = "usage: %s [-dmp] -f fname [-s sname] name [name ...]\n";
while ((c = getopt(argc, argv, "df:mps:")) != -1)
switch (c) {
case 'd':
debug = 1;
break;
case 'm':
mflag = 1;
break;
case 'p':
pflag = 1;
break;
case 'f':
fflag = 1;
fname = optarg;
break;
case 's':
sflag = 1;
sname = optarg;
break;
case '?':
err = 1;
break;
}
if (fflag == 0) { /* -f was mandatory */
fprintf(stderr, "%s: missing -f option\n", argv[0]);
fprintf(stderr, usage, argv[0]);
exit(1);
} else if ((optind+1) > argc) {
/* need at least one argument (change +1 to +2 for two, etc. as needeed) */
printf("optind = %d, argc=%d\n", optind, argc);
fprintf(stderr, "%s: missing name\n", argv[0]);
fprintf(stderr, usage, argv[0]);
exit(1);
} else if (err) {
fprintf(stderr, usage, argv[0]);
exit(1);
}
/* see what we have */
printf("debug = %d\n", debug);
printf("pflag = %d\n", pflag);
printf("mflag = %d\n", mflag);
printf("fname = \"%s\"\n", fname);
printf("sname = \"%s\"\n", sname);
if (optind < argc) /* these are the arguments after the command-line options */
for (; optind < argc; optind++)
printf("argument: \"%s\"\n", argv[optind]);
else {
printf("no arguments left to process\n");
}
exit(0);
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 09:30
Name the range function that would generate the following list of integers values: 0,1,2,3,4,5.
Answers: 1
question
Computers and Technology, 24.06.2019 02:30
Assume a class window with accessor method getwidth that accepts no parameters and returns an integer. assume further an array of 3 window elements named winarr, has been declared and initialized. write a sequence of statements that prints out the width of the widest window in the array.
Answers: 2
question
Computers and Technology, 24.06.2019 23:50
Which career involves analyzing various factors that influence the customer decision-making process? analyze various factors that influence the customer decision-making processes. reset next
Answers: 2
question
Computers and Technology, 25.06.2019 08:10
What refrigerant has been approved for new household refrigerators and freezers
Answers: 1
You know the right answer?
Use sample program from called getopt. c (provided below) Make a copy of getopt. c and call it gact...
Questions
question
Mathematics, 11.10.2019 05:50
question
Chemistry, 11.10.2019 05:50
question
Mathematics, 11.10.2019 05:50
Questions on the website: 13722361