I need help programming this question using C language.
This program uses input data entered in command line at the same time when the command or .exe file is entered. They are called command-line arguments. Because everything entered in command line is taken as a string, these arguments including the command itself or the .exe file name are stored in an array of char pointers, each pointer points to the first character of a string (i.e., argument). The inputs can be positive, negative, or zero as input data to the program. Duplicate numbers are allowed.
Requirements of main()
Below are prototypes of each function for your design and implementation.
// NOTE: In the case when second minimum/maximum do not exist, program will output a large/small number
#include <stdio.h>
#include <stdlib.h>
#define inf 100000
float min(int total, char *data[total])
{
float minValue = inf; // to store minimum number
for(int i = 1; i < total; i++)
{
float cur = atof(data[i]); // current number
if(minValue > cur)
minValue = cur;
}
return minValue;
}
float min2(int total, char *data[total])
{
float small; // minimum number
float s_small; // second minimum number
small = s_small = inf;
for(int i = 1; i < total; i++)
{
float cur = atof(data[i]);
if(small > cur)
{
s_small = small;
small = cur;
}
if(s_small > cur && cur != small)
{
s_small = cur;
}
}
return s_small;
}
float max(int total, char *data[total])
{
float maxValue = -inf; // to store largest number
for(int i = 1; i < total; i++)
{
float cur = atof(data[i]); // current number
if(maxValue < cur)
maxValue = cur;
}
return maxValue;
}
float max2(int total, char *data[total])
{
float large; // maxixum number
float s_large; // second maxixum number
large = s_large = -inf;
for(int i = 1; i < total; i++)
{
float cur = atof(data[i]);
if(large < cur)
{
s_large = large;
large = cur;
}
if(s_large < cur && cur != large)
{
s_large = cur;
}
}
return s_large;
}
void sum_avg(int total, char *data[total], float *sum, float *avg)
{
*sum = 0;
for(int i = 1; i < total; i++)
{
float cur = atof(data[i]);
(*sum) += cur;
}
(*avg) = (*sum)/(total - 1);
}
int main(int argc, char *argv[])
{
if(argc == 1)
{
printf("You must enter at least one number after program name.\n");
return 0;
}
printf("Numbers given: ");
for(int i = 1; i < argc; i++)
printf("%s ", argv[i]);
printf("\n");
printf("Minimum among them is: %f\n", min(argc, argv));
printf("Second minimum among them is: %f\n", min2(argc, argv));
printf("Maximum among them is: %f\n", max(argc, argv));
printf("Second maximum among them is %f\n", max2(argc, argv));
float sum = 0, avg = 0;
sum_avg(argc, argv, &sum, &avg);
printf("Sum of all numbers: %f\n", sum);
printf("Average of all numbers: %f\n", avg);
}
I need help programming this question using C language. This program uses input data entered in...
C Language Programming. Using the program below - When executing on the command line only this program name, the program will accept keyboard input and display such until the user does control+break to exit the program. The new code should within only this case situation “if (argc == 1){ /* no args; copy standard input */” Replace line #20 “filecopy(stdin, stdout);” with new code. Open read a text file “7NoInputFileResponse.txt” that contains a message “There were no arguments on the...
Command line input In C++ it is possible to accept command line arguments. Command-line arguments are given after the name of a program in command-line operating systems like Linux and are passed in to the program from the operating system. To use command line arguments in the program, it must first understand the full declaration of the main function, which until now has accepted no arguments. In fact, main can accept two arguments: one argument is number of command line...
Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...
need this in c programming and you can edit the code below. also give me screenshot of the output #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #define LINE_SIZE 1024 void my_error(char *s) { fprintf(stderr, "Error: %s\n", s); perror("errno"); exit(-1); } // This funciton prints lines (in a file) that contain string s. // assume all lines has at most (LINE_SIZE - 2) ASCII characters. // // Functions that may be called in this function: // fopen(), fclose(), fgets(), fputs(),...
I am writing a program in C++, which requires me to read an input text file using command line argument. However, I am using xcode on my Macbook to write C++ program, and use terminal instead of command. How do you use int main(int argc, char** argv[]) to read an input file. My professor requires us not to hard code the text file name like .open("example.txt"); Thank you!
Question:Many files on our computers, such as executables and many music and video files, are binary files (in contrast to text files). The bytes in these files must be interpreted in ways that depend on the file format. In this exercise, we write a program data-extract to extract integers from a file and save them to an output file. The format of the binary files in this exercise is very simple. The file stores n integers (of type int). Each...
Need C programming help. I've started to work on the program, however I struggle when using files and pointers. Any help is appreciated as I am having a hard time comleting this code. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LINE 100 #define MAX_NAME 30 int countLinesInFile(FILE* fPtr); int findPlayerByName(char** names, char* target, int size); int findMVP(int* goals, int* assists, int size); void printPlayers(int* goals, int* assists, char** names, int size); void allocateMemory(int** goals, int** assists, char*** names, int size);...
For the following task, I have written code in C and need help in determining the cause(s) of a segmentation fault which occurs when run. **It prints the message on line 47 "printf("Reading the input file and writing data to output file simultaneously..."); then results in a segmentation fault (core dumped) I am using mobaXterm v11.0 (GNU nano 2.0.9) CSV (comma-separated values) is a popular file format to store tabular kind of data. Each record is in a separate line...
C programming The program will require the following structure: struct _data { char *name; long number; }; The program will require command line arguments: int main(int argv, char **argc) { Where argv is the number of arguments and argc is an array holding the arguments (each is a string). Your program must catch any case where no command line arguement was provided and print a warning message (see below). You MUST include/use the following functions, defined as follows: int SCAN(FILE...
In c++ programming, can you please edit this program to meet these requirements: The program that needs editing: #include <iostream> #include <fstream> #include <iomanip> using namespace std; int cal_avg(char* filenumbers, int n){ int a = 0; int number[100]; ifstream filein(filenumbers); if (!filein) { cout << "Please enter a a correct file to read in the numbers from"; } while (!filein.eof()) { filein >> number[a]; a++; } int total = number[0]; for (a = 0; a < n; a++) {...