如何从文本文件中读取多个数字

所以这是我的代码,我不断收到分段错误。 如何格式化此代码以从文件中读取一组数字?

我的输入看起来像这样:82,46,71,56,44,12,100 62,67,64,65,62,39,68 68,90,78,57,76,45,82等

#include  int main () { FILE *input = fopen("input.txt", "r"); int line[7]; int store = 0, read; if(!input) { printf("Error: Filename \"input.txt\" not found!\n"); } store = 0; while(fscanf(input, "%d", &read) != EOF) { line[store] = read; store++; } printf("%d %d %d %d %d %d %d\n", line[0], line[1], line[2], line[3], line[4], line[5], line[6]); return(0); } 

将while循环条件更改为:

 while( store < sizeof(line)/sizeof(int) && fscanf(input, "%d", &read) != EOF) 

看起来你输入的数字更多,那么你有空间。