Code:
goon.dat
[COLOR=red]1.23[/color], 2.34, 3.45
[COLOR=red]1.34[/color], 2.12, 3.56
[COLOR=red]1.44[/color], 4.56, 6.78
Code:
double data[34][4];
void read_data()
{
char file_name[30]="goon.dat";
int i,j;
FILE *fp;
double X,Y,Z;
fp=fopen(file_name,"r");
if(fp==NULL){
printf("Cannot Open File?\n");
exit(1);
}
for(i=0;i<34;i++){
j=0;
X=data[i][j];
Y=data[i][j+1];
Z=data[i][j+2];
fscanf(fp,"%lf,%lf,%lf\n", &data[i][j],&data[i][j+1],&data[i][j+2]); printf("%f,%f,%f\n",data[i][j],data[i][j+1],data[i][j+2]);
double a[]={data[i][j]};
printf("%f",a[0]);
}
fclose(fp);
}
After run the codes, result showed
Code:
[COLOR=red]1.23[/color],[COLOR=red] 1.34[/color],[COLOR=red] 1.44[/color]
Why not the result is 1.23.I tried to get each value using pointer or array.