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, 03.07.2019 15:10
Apiston-cylinder with a volume of 0.25 m3 holds 1 kg of air (r 0.287 k/kgk) at a temperature of 100 c. heat transfer to the cylinder causes an isothermal expansion of the piston until the volume triples. how much heat is added to the piston-cylinder?
Answers: 3
question
Engineering, 04.07.2019 19:10
In general, how do thermosetting plastics compare to thermoplastics in mechanical and physical properties?
Answers: 3
question
Engineering, 04.07.2019 19:10
An external consultant recommends that a plant installs a bank of capacitors for power factor correction. this will reduce the peak electrical demand charges by an average of 93 kw every month. the plant current pays $13 per kw in peak demand charges. the capacitor bank will include 223 kw of fixed capacitors, and 183 of variable capacitors. the fixed capacitors cost $59 per kw, and the variable capacitors will cost $65 per kw. the consultant charges 21% of the equipment costs to install the capacitors. because this project will reduce the demand for the electric utility, they are prepared to provide a one-time rebate of $42 per kw of reduced demand. what is the simple payback period for this project (in years)?
Answers: 2
question
Engineering, 04.07.2019 19:10
Aplate of dimensions 3 m x 3 m is placed 0.37 mm apart from a fixed plate. the plate requires a force of 2n to move at speed of 45 cm/s. evaluate the viscosity of the fluid in between the plates
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