Home > Back-end >  The file output problems in C language
The file output problems in C language

Time:10-06

The source code
#include
#include
#include
#include
Int main (void)
{
Double a, [2].
int i;
FILE *fp;
If ((fp=fopen (" test. TXT ", "rt"))==NULL)
{
Printf (" can't open the file ");
Getch ();
exit(1);
}
Fscanf (fp, "% * [^ \ n]");
for(i=0; i<2; I++)
{
* 6 fscanf (fp, "% s % lf", & amp; A [0]);
}


Printf (" % lf \ n ", a [0]).
Printf (" % lf \ n ", a [1]).
fclose(fp);
}
My TXT file is
Score
Subjects 1:9 8 subjects 2:9 6
The final output is
96.0000
0.0000
Why just to read the second data in the first array element

CodePudding user response:

The
* 6 fscanf (fp, "% s % lf", & amp; A [0]);
Should be written as
* 6 fscanf (fp, "% s % lf", & amp; A [ I ]);
  • Related