I'm having trouble with how to find the count and sum of all numbers. Please help?
The file, called question1.txt, contains numbers:
1
2
3
4
5
0
0
0
-2
-2
Here's my code:
Code:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
FILE* spIn;
FILE* spOut; //for output file
int numIn;
spIn = fopen("c:\\aa\\question1.txt", "r");
if (!spIn)
{
printf("Could not open file\a\a\a\n");
exit (101);
} // if open fail
spOut = fopen("c:\\aa\\outData.txt", "w");
if (!spOut)
{
printf("Could not open file\a\a\a\n");
exit (101);
} // if open fail
while ((fscanf(spIn, "%d", &numIn)) == 1) {
fprintf(stdout,"\n%d ", numIn);
fprintf(spOut,"\n%d ", numIn); //write to output file
}
return 0;
}