【发布时间】:2012-01-12 20:17:03
【问题描述】:
我正在尝试使用 fscanf 读取文本文件。我在 ubuntu 上的 OpenCV 中使用 eclipse 工作。 以下是文本文件中的一些示例值 0 5 7 0.547619047619048 1 0.0274509803921569 1 0 6 8 0.541666666666667 1 0.0313725490196078 1 0 8 10 0.533333333333333 1 0.0392156862745098 1
但是 fscanf 读取的数组中的所有值都是零。这是读取值的代码部分
long double testd[1000][6]
FILE* fid1=fopen("file","r");
while((fscanf(fid1,"%Lf",&b))==1)
{
printf("%Lf\n",b);
testsamplecount=testsamplecount+1;
}
for (i=0;i<testsamplecount/6;i++)
{
fscanf(fid1,"%Lf %Lf %Lf %Lf %Lf %Lf",
&testd[i][0],&testd[i][1],
&testd[i][2],&testd[i][3],
&testd[i][4],&testd[i][5]);
}
【问题讨论】:
-
正如@ouah 在(已删除的)评论中所说,您需要
scanf()中的"%Lf"转换规范以获取long double;"%lf"用于double。 -
我试过这样做。但它没有读取文件。