Question
Problem: Write a program that behaves as described below. If the first command-line argument after the program name (argv[1]) is --help, print the usage information
Problem: Write a program that behaves as described below. If the first command-line argument after the program name (argv[1]) is --help, print the usage information for the program. If that argument is not --help, you are to expect argv[1] and subsequent arguments to be real numbers in formats acceptable to the sscanf() function of the C library or strings of ASCII chars that are not readable as real numbers. You are to read the numbers, calculate the number of, sum, minimum value, maximum value and average of those numbers, and if there are non-numbers write these to stdout as they are encountered. If there are no command line arguments (argc equals 1), print an error message and the usage information. If no numbers are among the command line arguments, print a suitable error message and the usage information following the non-numeric arguments present. Naming: Your submitted file is to be named p2.c. Output: Your programs output must be to stdout and of one of the four formats following, assuming argc and argv are the usual parameters for main() and where is argv[0], and rnum is any real number in decimal format. If argv[1] is --help, display the following. Usage: " --help" to display thus usage material. " [ ...]" to calculate the sum, minimum, maximum and mean of the real number arguments. Non-numeric values will be echoed to stdout. If real numbers are among the command line arguments, display the following as indicated above. For the sequence provided the following values were calculated. Found = Sum = Min = Max = Avg = Where the values in angle-brackets are the corresponding calculated values If there are no arguments following argv[0] (argc equals 1), display the following. *** ERROR: No command line arguments were found. Usage: " --help" to display thus usage material. " [ ...]" to calculate the sum, minimum, maximum and mean of the real number arguments. Non-numeric values will be echoed to stdout. The error message and usage information displayed when arguments are present but no numbers are found should be of similar format. Note that argv[0] is the program name, which should be used in generating the usage and error messages.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started