You are viewing our Forum Archives. To view or take place in current topics click here.
Help with C programming
Posted:
Help with C programmingPosted:
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
#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(DONT KNOW WHAT TO PUT HERE READ MY QUESTION BELOW)
count++;
(DONT KNOW WHAT TO PUT HERE READ MY QUESTION BELOW)
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);
return 0;
}
Okay this is an assignment! I have to find the min, max, and average of a data file using pointers. I have declared my pointers and everything is okay except for my while loop. I don't understand what to put in the () for the argument and I don't know how to find the min and max of my data file. Please help thanks! Will +rep to anyone who helps!
#2. Posted:
Status: Offline
Joined: Aug 01, 201113Year Member
Posts: 103
Reputation Power: 3
Why do you open two files
Find the min and max of what in the file ( its values or it's size)
Also pointers have a star after the data type e.g int*
It should be while (!end of file)
Find the min and max of what in the file ( its values or it's size)
Also pointers have a star after the data type e.g int*
It should be while (!end of file)
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Aug 14, 200915Year Member
Posts: 1,291
Reputation Power: 65
Status: Offline
Joined: Aug 14, 200915Year Member
Posts: 1,291
Reputation Power: 65
zeqzy wrote Why do you open two files
Find the min and max of what in the file ( its values or it's size)
Also pointers have a star after the data type e.g int*
It should be while (!end of file)
Try looping while the return value of fscanf doesn't equal 0.
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.