Here’s my code right now:
#include
#include
#define MXN 100
int readvalues(FILE *fin, float *x);
void range(float *x, int n, float *min, float *max);
int main (void) {
char input[MXN];
char output[MXN];
//This area under this text
printf(“Give input file name: “);
scanf(“%s”, input);
printf(“Give ouput file name: “);
scanf(“%s”,output)
//Confused on section above
float x[MXN];
int n;
float max, min;
// maybe FILE * fin = fopen(“samplesin.txt”, “r”);
// maybe FILE *fout = fopen(“maxminout.txt”, “w”);
n = readvalues(fin, x);
process_data(x, n, &min, &max);
fprintf(fout, “There are %d values in the arrayn”, n);
fprintf(fout, “The maximum value in the array is %fn”, max);
fprintf(fout, “The minimum value in the array is %fn”, min);
fclose(fin);
fclose(fout);
system(“notepad maxminout.txt”);
return 0;
}
int readvalues(FILE *fin, float *x) {
int n = 0;
while (fscanf(fin, “%f”, &x[n])!=EOF) {
n++;
}
return n;
}
void range(float *x, int n, float *min, float *max){
int i;
*min = x[0];
*max = x[0];
for(i = 0; i < n; ++i) {
if(x[i] < *min) {
*min =x[i];
}else if(x[i] > *max) {
*max = x[i];
}
}
return;
}
//////////////////////////
just need help on the first two steps needed.
5. In some programs we would like to be able to determine the input and output filenames at the time that the program is executed. Modify your maxmin.c program from Assignment 8 so that the main program prompts the user for the two filenames and passes the input filename to the readvalues() function. The function readvalues() now opens the input file to read the data and closes it when done. This program uses a second function, range(), to find the maximum and minimum of a set of floats stored in the input file. Your main must use the following steps: • prompt user for the input and output file names. • call the function readvalues() to open the input file, read the values from the intput file into the array x, and return the value of n number of values in the file). . call the function range() which computes the maximum and minimum values found in the array x • open the output file to write out the results of the run the maximum and minimum values). The program should interact with the user as follows: Enter the input filename samplesin.txt Enter the output filename: samplesout.txt Use the same input file, samplesin.txt, as in Assignment 8. Then your output file should be the same as for Assignment 8, maxminout.txt. Show transcribed image text 5. In some programs we would like to be able to determine the input and output filenames at the time that the program is executed. Modify your maxmin.c program from Assignment 8 so that the main program prompts the user for the two filenames and passes the input filename to the readvalues() function. The function readvalues() now opens the input file to read the data and closes it when done. This program uses a second function, range(), to find the maximum and minimum of a set of floats stored in the input file. Your main must use the following steps: • prompt user for the input and output file names. • call the function readvalues() to open the input file, read the values from the intput file into the array x, and return the value of n number of values in the file). . call the function range() which computes the maximum and minimum values found in the array x • open the output file to write out the results of the run the maximum and minimum values). The program should interact with the user as follows: Enter the input filename samplesin.txt Enter the output filename: samplesout.txt Use the same input file, samplesin.txt, as in Assignment 8. Then your output file should be the same as for Assignment 8, maxminout.txt.
Expert Answer
Answer to Here’s my code right now: #include #include #define MXN 100 int readvalues(FILE *fin, float *x); void range(float *x, in…