subject
Engineering, 04.04.2020 04:28 jenhowie2944

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: 3

Another question on Engineering

question
Engineering, 04.07.2019 18:10
The drive force for diffusion is 7 fick's first law can be used to solve the non-steady state diffusion. a)-true b)-false
Answers: 1
question
Engineering, 04.07.2019 18:10
The thermal expansion or contraction of a given metal is a function of the f a)-density b)-initial temperature c)- temperature difference d)- linear coefficient of thermal expansion e)- final temperature f)- original length
Answers: 2
question
Engineering, 04.07.2019 18:20
What is the heat treatment of metals? what is the benefit of it? why and how it's useful? answer in details, do not write by hand.
Answers: 3
question
Engineering, 04.07.2019 18:20
Amixture of slurry and mud is to be pumped through a horizontal pipe of diameter 500 mm. the fluid behaves as a bingham plastic with a yield stress of 30 pa and viscosity 0.04 pa.s. describe the effects of the shear stress through a transverse section of the pipe by plotting the variation in shear stress and velocity profile: (i) just before the slurry starts to move (ii) as the slurry flows when the pressure gradient is double that in part (i)
Answers: 3
You know the right answer?
Use sample program from called getopt. c (provided below)
Make a copy of getopt. c and call it...
Questions
question
English, 29.08.2019 01:30
question
Mathematics, 29.08.2019 01:30
question
Mathematics, 29.08.2019 01:30
question
Mathematics, 29.08.2019 01:30
Questions on the website: 13722361