fscanf doesn't seem to behave as described for me. Specifically, it seems to only store zero.
When I run this structure, I expect floating point numbers to be read from the file one-by-one, stored temporarily in 'data', then printed to the screen.
Code:
if((fp = fopen(argv[1],"rb"))==NULL){
printf("cannot open %s\n", argv[1]);
}
else{
for(i=0; i < 3; i++){
for(j=0; j<3; j++){
fscanf(fp, "%f", &data);
printf("%f \n",data);
}
}
fclose(fp);
}
Instead, the output is:
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
The input file is:
0.000000 0.000000 0.000000
0.000000 1.000000 2.000000
0.000000 2.000000 4.000000
Is it clear what I am doing wrong?
Thanks again!