I just started to learn C. This is a very simple question, so please forgive me for posting this here.
I have a set of data in, let's say, .txt file. this txt file is in tab-delimited, like
1 4 9
2 6 10
3 7 11
4 8 12
Using fopen and while loop, I managed to print out the data line by line.
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp;
char filename[80], ss[256];
printf("Filename=: ");
gets(filename);
if ((fp=fopen(filename,"r")) == NULL)
{
printf("Cannot open file.\n");
exit(1);
}
while (fgets(ss,256,fp) != NULL)
{
printf("%s",ss);
}
fclose(fp);
return 0;
}
What I would like to do as a first practice is compute the mean of each column. This data is recorded in x.xxx, so I should use double, right? So I would define
double mean(double x);
double arr[MAX_SIZE][MAX_SIZE];
int j,k;
and
double mean(double x)
{
double m;
for (k=1;k<=MAX_SIZE;k++)
{
m=data[][k]/MAX_SIZE;
std=
}
return m;
}
Is this right? I appreciate if someone could help. I just want to take advantage of compiler to shorten computing times as matlab takes a lot of time to process large data......
Thanks very much.
Taka