Question
Language is C, not C++. Error with strcmp. Copy code and run for specifics. #include #include #include #define HELP --help int main(int argc, char **argv)
Language is C, not C++. Error with strcmp. Copy code and run for specifics.
#include
#include
#include
#define HELP "--help"
int main(int argc, char **argv)
{
// declaration of variables
int totalCount = argc;
char charArray[100] = {0};
int realArray[100] = {0};
char convertedValue = 0;
int invalidNum = 0;
int validNum = 0;
int sum = 0;
int max = 0;
int min = 0;
float avg = 0;
int realArrayCount = 0;
printf("String = %s ", argv[1]);
if(!(strcmp((char*)argv[1], HELP)))
{
printf("it's a help... Please check and proceed with compilation ");
}
Error with strcmp. Copy code and run for specifics
else
{
for(int i = 2; i
{
sscanf(argv[i], "%d", &convertedValue);
if(convertedValue == 0)
{
charArray[realArrayCount] = argv[i];
invalidNum++;
printf("Invalid string = %s ", argv[i]);
}
else
{
validNum++;
realArray[realArrayCount] = convertedValue;
printf("realArray[%d}: %d ", realArrayCount, realArray[realArrayCount]);
}
realArrayCount++;
}
}
printf("Total Valid Numbers: %d, Total Invalid Numbers: %d ", validNum, invalidNum);
for( int i = 0; i
{
sum += realArray[i];
}
printf("Sum: %d ", sum);
avg = sum / validNum;
printf("Average: %f ", avg);
for(int i = 0; i
{
for(int j = i + 1; j
{
if(realArray[i] > realArray[j])
{
int k;
k = realArray[i];
realArray[i] = realArray[j];
realArray[j] = k;
}
}
}
max = realArray[validNum - 1];
min = realArray[0];
printf("Maximum value: %d ", max);
printf("Minimum value: %d ", min);
printf("Sum: %d ", sum);
printf("Average: %f ", avg);
}
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 (C integer, float or double types) in formats acceptable to the sscanffunction 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 (argc 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 program's output must be to stdout and of one of the four formats following. assuming argc and argu are the usual parameters for main and whereStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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