如果有人能够帮助我完成“程序”,那将会很好。我正在尝试读取csv文件并将其移至2D数组。它停在17号线(满分200)。使用fgets程序停止读取文件
int main()
{
FILE * pFile;
double **tab;
char bufor [100];
int i=0;
tab = (double**)malloc(sizeof(double*));
pFile = fopen ("sygnal1.csv" , "r");
if (pFile == NULL) printf("Error");
else
while (fgets (bufor , 100 , pFile))
{
tab[i] = (double *) malloc(2 * sizeof(double));
sscanf(bufor, "%lf, %lf,", &tab[i][0], &tab[i][1]);
printf("%lf.%lf.\n",tab[i][0],tab[i][1]); //It's here only for testing
i++;
}
printf("number of lines read %d\n",i);
fclose (pFile);
system("PAUSE");
return 0;
}
您还没有完全为'tab'分配内存。 –
此外,它很小,但我相当肯定你的意思是缓冲区而不是bufor! – Benj
我遇到了最大的问题。不知道为什么它是错的。我正在关注这个例子[链接](http://stackoverflow.com/questions/4237428/two-dimensional-array-matrix-memory-allocation-troubles) – Norrec