以下是我所做的一个例子。我的逻辑错在哪里?我打开文件并声明一个大小的数组。但我似乎无法填补数组。
#include <stdio.h>
int main()
{
/*open the file from use input*/
printf("what file stores your cities temperature data?\n");
char filename[20];
scanf("%s", filename);
FILE *ifp;
ifp=fopen(filename, "r");
if (ifp==NULL)
{
printf("File Open Error...");
}
else
{
/*declare an array and fill with file data?*/
double cityarray [6102][4];
int i,j;
for(i=0;i<6102;i++)
{
for(j=0;j<4;j++)
{
fscanf(ifp, "%.1lf", cityarray[i][j]);
printf("%.1lf\t",cityarray[i][j]);
}
printf("\n");
}
fclose (ifp);
}
return 0;
}
答案 0 :(得分:1)
尝试:
fscanf(ifp, "%.1lf", &cityarray[i][j]);