Code:
/*
program: proj4
Name: Jordan Ward
Email: jw363912@ohio.edu
Description: This program reads from an input file and
prints out the min, max, and average of the numbers.
*/
#include <stdio.h>
int main(void)
{
FILE *inp;
FILE *out;
int count = 0;
int sum = 0;
int min;
int max;
int input_status;
inp = fopen("data.dat", "r");
out = fopen("data.out", "w");
input_status = fscanf(inp, "%d", &min);
while(input_status == 10)
count++;
if(min > input_status)
max = min;
else if(min < input_status)
max = input_status;
sum++;
[ Wrote 49 lines ]
bash-3.00$ !g
gcc assign4.c
bash-3.00$ gcc -Wall assign4.c
assign4.c: In function 'main':
assign4.c:49:1: warning: control reaches end of non-void function
bash-3.00$ nano assign4.c
GNU nano 2.2.4 File: assign4.c
int max;
int input_status;
inp = fopen("data.dat", "r");
out = fopen("data.out", "w");
input_status = fscanf(inp, "%d", &min);
while(input_status == 1)
count++;
(not sure what to put here read my question down low)
sum++;
input_status = fscanf(inp, "%d", &min);
fprintf(out, "Minimum value = %d", min);
fprintf(out, "Maximum value = %d", max);
fprintf(out, "Average value = %4lf", (double) (min + max) / 2);
fclose(inp);
fclose(out);
}
Okay this is an assignment and I have to make a pointer called whatever i want but i need two pointers, one for data file and one for an output file. I am having trouble in the while loop, I don't understand what to put in the () for the argument and then I don't understand how to find the min and max of my data file. Thanks!