Hi all, can someone please help me with my code:
Its suppose to input a text file of values then display them and give the max and its index, and inputed values are floats.
But I can seem to get the max right.
Thanks
#include <stdio.h>
int main()
{
FILE *in;
float input[500]; // Allows the array to input a maximum of 500 values
if
((in = fopen("input.txt", "r")) == NULL) // Opens the text file containing values
{
printf("The file cannot be opened\n"); // Displays message if text file cannot be opened
}
printf("Values from inputed text file:\n");
int u = 1,c = 1;
while
(fscanf(in, "%f", &input[u])!=EOF)
{
printf("%f\n", input[u]); // Displays the inputed values
u ++;
c = u;
}
float max = 0;
for
(u = 1; u <= c; u ++)
{
if
(max < input[u])
{
max = input[u];
c = u;
}
}
printf("The max value is = %f and is at location %u\n", max, c);
fclose(in);
return 0;
}