Question: I need help solving the following function. The language is C. ///////////////////////////////////////////////////////////////////////////////////////////////////////// Strings.h ///////////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef STRINGS_H #define STRINGS_H #include void parse_args(int argc, char *argv[], int

I need help solving the following function. The language is C.

///////////////////////////////////////////////////////////////////////////////////////////////////////// Strings.h ///////////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef STRINGS_H #define STRINGS_H #include

void parse_args(int argc, char *argv[], int *cflag, int *wflag, int *nflag, int *lflag, FILE **outfile, int *name_len);

#endif // STRINGS_H ///////////////////////////////////////////////////////////////////////////////////////////////////////// Challenge.c ///////////////////////////////////////////////////////////////////////////////////////////////////////// #include "strings.h"

#include #include #include

//1. Use getopt() to parse command line flags, including some that take argument values

// Process command line arguments for a wc-like program // @param argc: number of command line arguments, including the program name // @param argv: array of pointers to strings, one for each argument // @param cflag: address of a 0/1 integer variable - an output of the function // @param wflag: address of a 0/1 integer variable - an output of the function // @param nflag: address of a 0/1 integer variable - an output of the function // @param lflag: address of a 0/1 integer variable - an output of the function // @param outfile: address of a FILE * variable - an output of the function // @param name_len: address of an int variable - an output of the function void parse_args(int argc, char *argv[], int *cflag, int *wflag, int *nflag, int *lflag, FILE **outfile, int *name_len) { // using the getopt library routine, process the command line // arguments given by argc and argv, looking for these options: // -c, -w, -n, -l: set the corresponding flag's int variable to 1 // -o name: try to open for output a FILE with the given name; if that // fails, print to stderr "Error opening output file: xxx " where // xxx is the name of the file, then exit (not return) // -f nnn: set the name_len's int to the integer value given by nnn; // you may use the atoi library function to do the necessary conversion // Default values: // If none of -c, -w, -n, and -l are given, set cflag, wflag, and lflag // (i.e., set the int variable to 1), and unset lflag (value 0). It is // probably easiest to (1) set all the flags' ints to 0 at the beginning; // (2) set individual flags as they are encountered, also remembering if // any have been set; and (3) check for the default case after the // argument processing loop. // If -o is not given, the default output FILE * is for outfile is stdout. // If -f is not given, the default value for name_len is 20. // For outfile and name_len, it is probably easiest to set their default at // the beginning. That way no later check is required. return; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!