fscanf

Hi I am new to c programming and wanted to read some data from a file. I am using the fscanf function and the output are very odd nymbers. Here is the program and the sortened version of data file.
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h>
#include <stdlib.h>
main (){
        int i;
        FILE *fp;
        double tt1, tt2, tt3;
        fp=fopen("test.txt","r");
        for (i=0; i<9; i++){
                fscanf(fp,"%16.8e %16.8e %16.8e\n",&tt1,&tt2,&tt3);
                printf("%16.8e %16.8e %16.8e\n",tt1,tt2,tt3);
        }
}

**********************************************************************
Datafile ----->
**********************************************************************
8.40187717e-01 3.94382927e-01 7.83099224e-01
7.98440033e-01 9.11647358e-01 1.97551369e-01
3.35222756e-01 7.68229595e-01 2.77774711e-01
5.53969956e-01 4.77397052e-01 6.28870925e-01
3.64784473e-01 5.13400910e-01 9.52229725e-01
9.16195068e-01 6.35711728e-01 7.17296929e-01
1.41602555e-01 6.06968876e-01 1.63005716e-02
2.42886771e-01 1.37231577e-01 8.04176754e-01
1.56679089e-01 4.00944394e-01 1.29790447e-01
1.08808802e-01 9.98924518e-01 2.18256905e-01
**********************************************************************

Please Help ?
Last edited on
I think is better if you use C++ instead of C, for input/output with files in C++ see http://www.cplusplus.com/doc/tutorial/files.html
Thanx for the advice. However I solved that out after few trial and errors.
Last edited on
Topic archived. No new replies allowed.