我写了个函数,将数组中的数据写入txt文件,以后用另一个函数读出来。
现在的问题是,可以用fprintf()写进去,但是用fscanf()读不出来,txt文件
中格式如下:
384 85.8 -384 484 86 -384
384 85.8 -384 484 86 -384
384 85.8 -384 484 86 -384
384 85.8 -384 484 86 -384
384 85.8 -384 484 86 -384
384 85.8 -384 484 86 -384
384 85.8 -384 484 86 -384
384 85.8 -384 484 86 -384
.
.
.读取函数如下:全局变量:
float P_View[2000][3];
float P_View1[2000][3];
void baiscobj::LoadP()
{
int i,j;
FILE *file1; for (i = 0 ; i < 1999; i++)
{
P_View[i][0] = 0.0;
P_View[i][1] = 0.0;
P_View[i][2] = 0.0;
P_View1[i][0] = 0.0;
P_View1[i][1] = 0.0;
P_View1[i][2] = 0.0;
} file1 = fopen( "d:\\ViewP.txt", "r" );
if ( file1 == NULL)
{
exit(-1);
} for (j = 0 ; j < 1999; j++)
{
fscanf( file1, "%f %f %f %f %f %f\n", &P_View[i][0],&P_View[i][1],
&P_View[i][2],&P_View1[i][0],&P_View1[i][1],&P_View1[i][2]);
} fclose(file1);
}
现在的问题是,可以用fprintf()写进去,但是用fscanf()读不出来,txt文件
中格式如下:
384 85.8 -384 484 86 -384
384 85.8 -384 484 86 -384
384 85.8 -384 484 86 -384
384 85.8 -384 484 86 -384
384 85.8 -384 484 86 -384
384 85.8 -384 484 86 -384
384 85.8 -384 484 86 -384
384 85.8 -384 484 86 -384
.
.
.读取函数如下:全局变量:
float P_View[2000][3];
float P_View1[2000][3];
void baiscobj::LoadP()
{
int i,j;
FILE *file1; for (i = 0 ; i < 1999; i++)
{
P_View[i][0] = 0.0;
P_View[i][1] = 0.0;
P_View[i][2] = 0.0;
P_View1[i][0] = 0.0;
P_View1[i][1] = 0.0;
P_View1[i][2] = 0.0;
} file1 = fopen( "d:\\ViewP.txt", "r" );
if ( file1 == NULL)
{
exit(-1);
} for (j = 0 ; j < 1999; j++)
{
fscanf( file1, "%f %f %f %f %f %f\n", &P_View[i][0],&P_View[i][1],
&P_View[i][2],&P_View1[i][0],&P_View1[i][1],&P_View1[i][2]);
} fclose(file1);
}
for (j = 0 ; j < 1999; j++)
{
fscanf( file1, "%f %f %f %f %f %f\n", &P_View[i][0],&P_View[i][1],
&P_View[i][2],&P_View1[i][0],&P_View1[i][1],&P_View1[i][2]);
}
呵呵,变量用错了,循环变量是j,循环内用的是i.
=> for (j = 0
=> P_View[i][0]
现在给分。