Question: This needs to b written in C language: #include #include /*#include #include */ #define OPTIONS1 ./program name, option, num1, num2 void dispErr(char* , char*); void
This needs to b written in C language:
#include
#include
/*#include
#include
#define OPTIONS1 "./program name, option, num1, num2"
void dispErr(char* , char*);
void prnArgs(FILE*, int, char *[]);
/*This current version uses OPTIONS1 defined above for the format of command line argument*/
/* modify your code so that you can do the followings: */
/* Option =2 */
/*void Highest( your argument); to use float numbers from command line to get the highest number*/
/* Option =1 */
/*void Avg( your argument); to use float numbers from command line to get float average*/
int main( int argc, char *argv[] ) {
int i, sum;
FILE *fpL7;
fpL7 = fopen("Lab7w1.txt", "w+b");
if (fpL7==NULL)
{
printf(" File Lab7.txt does not open");
exit(EXIT_FAILURE);
/*return 0;*/
}
else {
printf("Output file opened succcessfully ");
}
prnArgs(fpL7, argc, argv);
if (argc
dispErr(argv[0], OPTIONS1);
printf(" Enter at least 4 parameters");
exit(EXIT_FAILURE);
/*return 0;*/
}
if (atoi(argv[1])==1)
{
printf(" Option: %s --> Average Selected", argv[1]);
fprintf(fpL7, " Option: %s --> Average Selected", argv[1]);
/*Avg(your arguments);*/
}
if (atoi(argv[1])==2)
{
printf(" Option: %s --> Highest number Selected", argv[1]);
fprintf(fpL7, " Option: %s --> Highest number Selected", argv[1]);
/*Highest(your arguments)*/
}
/*This code segment is how you perform a integer sum on the arguments (except first two) and prints to console */
for( i = 0; i
sum += atof(argv[i]);
}
printf(" ----------------");
printf(" Result = %d", sum);
fclose(fpL7);
return 0;
}
/*This function prints the arguments by taking three arguments: (i)file pointer (ii) argc and (iii)*argv[] */
void prnArgs(FILE* fpL7, int argc, char *argv[]){
int i;
fprintf (fpL7, "Number of arguments = %d ", argc);
for( i = 0; i
printf("Argv[%d] = %s ", i, argv[i]);
fprintf(fpL7, "Argv[%d] = %s ", i, argv[i]);
}
fprintf(fpL7, " --------------------------");
fprintf(fpL7, " Arguments printing completed successfully");
}
/*void Avg( your argument){
Your code here
}*/
/*void Highest( your argument){
Your code here
}*/
void dispErr(char* a1, char* b1){
printf(" Your program %s should have following option parameter format: %s", a1, b1);
}

3. Do the following modifications: 1] write a function Highest (which is already outline inside the code) will take arguments like void prnArgs(FILE* fpL7, int argc, char *argvll) then: finds highest number for except first two arguments print to console print to file 2] write a function Avg (which is already outline inside the code) will take arguments like void prnArgs(FILE* fpL7, int argc, char *argv[I) then: find avg of arguments except first two print to console print to file 3. Do the following modifications: 1] write a function Highest (which is already outline inside the code) will take arguments like void prnArgs(FILE* fpL7, int argc, char *argvll) then: finds highest number for except first two arguments print to console print to file 2] write a function Avg (which is already outline inside the code) will take arguments like void prnArgs(FILE* fpL7, int argc, char *argv[I) then: find avg of arguments except first two print to console print to file
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
