#include "args-strings.h" #include #include #include // Function that the auto-grader u

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

#include "args-strings.h" #include #include #include // Function that the auto-grader u

Post by answerhappygod »

Include Args Strings H Include Stdlib H Include String H Include Unistd H Function That The Auto Grader U 1
Include Args Strings H Include Stdlib H Include String H Include Unistd H Function That The Auto Grader U 1 (81.15 KiB) Viewed 20 times
#include "args-strings.h" #include <stdlib.h> #include <string.h> #include <unistd.h> // Function that the auto-grader uses to reset getopt() // Don't worry about it // (I mean, feel free to mess with it, but you'll fail the auto-grader tests.) void reset_getopt() { optind = 1; } // 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) { //TODO // using the getopt library routine, process the command line // arguments given by argc and argv, looking for these options: // -c, -W, -n, -1: 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\n" 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 -1 are given, set cflag, wflag, and lflag // (i.e., set the int variable to 1), and unset Iflag (value (). 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; h
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply