Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 expectargv[1]and subsequent arguments to be real numbers(C, integer, float, or double types)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, count them and calculate the sum, minimum value, maximum value and average of those numbers, and if there are non-numbers write these to stdout as they are encountered, one per line. If there are no command-line arguments other than the program name(arc equals 1), print a suitable 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 rnumis any real number in decimal format.If argv[1]is --help, display the following.Usage: --help display this usage material. [ ...]calculate the sum, minimum, maximum and mean of the real number command line arguments. Non-numeric values will be echoed to the standard output device, one per line, with the numeric results printed following the non-numeric lines. If real numbers are among the command line arguments, echo the non-numeric command-line arguments to stdout, then display the following as indicated in the above usage text. For the sequence provided the following values were calculated.Found = Sum = Min = Max = Mean = Where the values indicated in angle-brackets are the corresponding calculated values. Note that you are NOT to replicate the angle-brackets. For example, the entire string is to be replaced with the sum.If there are no arguments following argv[0](argcequals 1), display the following.*** ERROR: No command line arguments were found.Usage: --helpdisplay this usage material. [ ...]calculate the sum, minimum, maximum and mean of the real number command line arguments.Non-numeric values will be echoed to the standard output device, one per line, with the numeric results printed following the non-numeric lines. The error message and usage information displayed when arguments are present but no numbers are found should be of a similar format. Note that argv[0]is the program name, which should be used in generating the usage and error messages. In the above, is to be replaced by the name of the program as run, without any filename extension, while [ ...]is to be displayed, not replaced. You are to obtain the name of the program from argv[0], the first command-line argument. Preferably you should pare the path from the name, but this is not required. How to pare the path from the name will be discussed, though.

This must be written in C, not C++.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions

Question

1. Outline the listening process and styles of listening

Answered: 1 week ago

Question

4. Explain key barriers to competent intercultural communication

Answered: 1 week ago