In some programs we would like to be able to determine the i
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. The main function should open the specified output file to write out the results of the run. The program should interact with the user as follows: Enter the input filename : samplesin.txt Enter the output filename: samplesout.txt. Then your output file should be the same as maxminout.txt:
There are 80 values in the array
The maximum value in the array is 63.605999
The minimum value in the array is 4.808900
Here is the code to work with;
#include
 #include
void range(float x[], int size, float *max, float *min);
 int readvalues(FILE *fin);
int main(void) {
   
        float max, min, value;
 int n = 0;
 float x[100];
 FILE *fin = fopen(\"samplesin.txt\", \"r\");
 FILE *fout = fopen(\"maxminout.txt\", \"w\");
   
 while(fscanf(fin, \"%f\", &value)!=EOF) {
   
                x[n] = value;
 n++;
 }
   
 range(x, readvalues(fin), &max, &min);
   
 fprintf(fout, \"There are %d values in the array\ \ \", readvalues(fin));
 fprintf(fout, \"The maximum value in the array is %f\ \ \", max);
 fprintf(fout, \"The minimum value in the array is %f\ \", min);
   
 fclose(fin);
 fclose(fout);
 system(\"notepad.exe maxminout.txt\");
 return 0;
 }
int readvalues(FILE *fin)
 {
 int n = 0;
 float f;
 fin = fopen(\"samplesin.txt\", \"r\");
   
 while(fscanf(fin, \"%f\", &f)!=EOF) {
 n++;
 }
   
 fclose(fin);
   
 return n;
 }
 void range(float x[], int size, float *max, float *min)
 {
 int i;
 *max = x[0];
 *min = x[0];
   
 for(i=1; i < size; i++) {
   
                if(x[i] > *max){
               
                *max = x[i];
            }
   
                if(x[i] < *min){
                   
                *min = x[i];
            }
 }
 return;
 }
Solution
your program is working fine but you have do small mistake remove this (system(\"notepad.exe maxminout.txt\");) one. and for user friendly i have to print the input file name and output file name what you want and what the output will print first hear display then print in minmax.txt file.
#include<stdio.h>
void range(float x[], int size, float *max, float *min);
 int readvalues(FILE *fin);
 int main(void)
 {
   
 float max, min, value;
 int n = 0;
 float x[100];
 char inFile[50],outFile[50];
FILE *fin = fopen(\"C:\\\\Users\\\\Mittu\\\\Desktop\\\\cheggdes\\\\samplesin.txt\", \"r\");
 FILE *fout = fopen(\"C:\\\\Users\\\\Mittu\\\\Desktop\\\\cheggdes\\\\maxminout.txt\", \"w\");
   
 while(fscanf(fin, \"%f\", &value)!=EOF) {
   
 x[n] = value;
 n++;
 }
   
 range(x, readvalues(fin), &max, &min);
printf(\"Enter the input filename : \");
 scanf(\"%49s\", &inFile);
printf(\"\ Enter the output filename : \");
 scanf(\"%49s\", &outFile);
printf(\"There are %d values in the array\ \ \", readvalues(fin));
 printf(\"The maximum value in the array is %f\ \ \", max);
 printf(\"The minimum value in the array is %f\ \", min);
 fprintf(fout, \"There are %d values in the array\ \ \", readvalues(fin));
 fprintf(fout, \"The maximum value in the array is %f\ \ \", max);
 fprintf(fout, \"The minimum value in the array is %f\ \", min);
   
 fclose(fin);
 fclose(fout);
 return 0;
 }
 int readvalues(FILE *fin)
 {
 int n = 0;
 float f;
 fin = fopen(\"C:\\\\Users\\\\Mittu\\\\Desktop\\\\cheggdes\\\\samplesin.txt\", \"r\");
   
 while(fscanf(fin, \"%f\", &f)!=EOF) {
 n++;
 }
   
 fclose(fin);
   
 return n;
 }
void range(float x[], int size, float *max, float *min)
 {
 int i;
 *max = x[0];
 *min = x[0];
   
 for(i=1; i < size; i++) {
   
 if(x[i] > *max){
   
 *max = x[i];
 }
   
 if(x[i] < *min){
   
 *min = x[i];
 }
 }
 return;
 }



