/* args.c Jeff Ondich, 27 March 2023 Modified by Tanya Amert for Fall 2024 A tiny experiment with command-line arguments. Compile as usual: gcc -Wall -Werror -g -o args args.c Run with zero or more command-line arguments: ./args ./args cheddar lulu ./args a b c d e f g whatever blah blah blah Read the code to figure out what: argc means argv[0] points to argv[k] points to for k > 0 Also, read the code to figure out how to get a picture of a beaver to print out. */ #include #include // Method declarations void print_beaver(); // Echos command-line arguments back to the user, // and in a special case, displays a beaver! // // Parameters: // - argc: integer number of command-line arguments // - argv: pointer to array of command-line arguments (as chars) // // Returns: an integer status (0 if the program completed successfully) int main(int argc, char *argv[]) // read this as an array of strings { printf("Your command line includes %d arguments:\n", argc); for (int k = 0; k < argc; k++) { printf(" argv[%d] --> %s\n", k, argv[k]); } if (argc >= 3 && strcmp(argv[2], "beaver") == 0) { printf("\nCongratulations! You get an extra surprise!\n\n"); print_beaver(); } return 0; } // Displays a beaver to standard output. void print_beaver() { // Note: modified the image slightly to take up less horizontal space printf(" A\n"); printf(" ___ / \\\n"); printf(" .=\" \"=._.---. / \\ ____________\n"); printf(" .\" c \' Y\'`p / \\ /) -\n"); printf(" / \\ `\\ w_/ :~~~~~~~: / )- . -\n"); printf(" jgs | ) / / | | < ) -- \n"); printf(" ______| /__-\\ \\_=.\\ | | \\ ) - -\n"); printf("(XXXXX/\'`------)))`=-\'\"`\'\"_____/__/__\\___\\__ _ \\)___________\n"); printf(" ~~~~~\n"); printf("\nhttps://www.asciiart.eu/animals/beaver\n"); }