I am writing a program using C just to find the max and min numbers from my input file that contains about 500 floating numbers such as 54.54. I can get the program to run but the output says my min is 0 and my max is 54.88 which is the very first number from the file. Here is what i have so far.
#include <stdio.h>
int main(int argc, const char * argv[])
{
FILE * fp;
fp=fopen("file.txt","r");
if (fp==NULL)
{
printf("Failed to open");
}
float i;
float min ;
float max ;
{
fscanf( fp, "%f", &i);
if (i < min)
min = i;
if (i > max)
max = i;
}
printf("Data range is: %f %f \n", min, max);
return 0;
}