This is what I've adjusted it to, except the final specification of the assignment is that I must incorporate the implementation and function call of the function MAX and the function MIN. I'm having trouble doing so, if anyone could lend a helping hand I would greatly appreciate it.
Code:
#include <stdio.h>
int main()
{
FILE *sensor;
int num, min, max, sum, count, first;
sensor = fopen("C:\\Users\\joseph.labelle\\Documents\\data.txt", "r");
if (sensor != NULL)
{
for (sum = count = first = 0;
fscanf(sensor, "%d", &num) == 1; sum += num, ++count)
if (!first)
{
min = max = num; first = 1;
}
else if (num > max) max = num;
else if (num < min) min = num;
fclose(sensor);
printf("count = %d, min = %d, max = %d, sum = %d, avg = %.1lf\n",
count, min, max, sum, sum / (double) count);
}
else
{
printf("Unable to read file 'C:\\Users\\joseph.labelle\\Documents\\data.txt'.\n" );
}
return 0;
}
Thanks for all your help!