Hello i'm currently working on an i/o file dealing with arrays, basically I have to get the information from an input file get the sum and the average for each row and then get the sum, average, and standard deviation for each column. I got the rows down but i'm having a lot of trouble with the arrays since I barely started learning about them. Any help is appreciated
Code:
#include<stdio.h> /* defines printf, scanf, fprint, fscanf, fopen, fclose*/
int main()
{
double n1, n2, n3,sum, mean;
double *sum1, *sum2, *sum3;
double *ave1, *ave2, *ave3;
double *sd1, *sd2, *sd3;
int count;
FILE *inp, /*input data*/
*outp; /*output data*/
/* Open the input and output files. */
inp = fopen("numbers.dat", "r");
outp = fopen("result.out", "w")
/* Displays the table layout */
printf(" Count #1 #2 #3 Sum Average\n");
printf(" ---- --------- -------- -------- -------- --------\n");
/* while loop scanning input file rows and printing output results */
while (fscanf(inp, "%lf %lf %lf", &n1, &n2, &n3) != EOF) {
sum=n1+n2+n3;
mean=sum/3;
count=count+1;
printf("%9.3d %9.3lf %9.3lf %9.3lf %9.3lf %9.3lf\n", count, n1, n2, n3, sum, mean);
fprintf(outp, "%9.3d %9.3lf %9.3lf %9.3lf %9.3lf %9.3lf\n", count, n1, n2, n3, sum, mean);
}
printf(" ---- --------- -------- -------- -------- --------\n");
/* Use only the first two columns. */
for ( count = 0; count < 17; ++count )
{
printf("sum1 = %9.3f, sum2 = %9.3f, sum3 = %9.3f\n", sum1[count], sum2[count], sum3[count]);
}
printf(" Sum\n");
fclose(inp);
fclose(outp);
system("pause");
return (0);
}