我想读取一个文本文件并将其数据放入二维数组中。此代码适用于像 0 1 1 1 0 1 1 0 1 1 1 1 这样的小文本文件,但会为大文本文件和 648x512 数组提供分段错误。可能是什么问题呢?有什么更好的代码可以做到这一点?
链接到一个大的txt文件:
http://mimoza.marmara.edu.tr/~omer.korcak/courses/CSE246%20-%20Spring2012/squares.txt
#include<stdio.h>
FILE *input;
int x=0, y=0, R=0, C=0,c=0;
int main()
{
input = fopen("squares.txt", "r");
C = 512;
R = 648;
int M[R][C];
for(x = 0; x < R; ++x ) {
for(y = 0; y < C; ++y ) {
fscanf( input, "%d", &c );
M[x][y]=c;
}
}
}