C语言如何从文件读入数组

2024-12-31 05:53:55
推荐回答(1个)
回答1:

主要语句如下:

FILE *fin;
int arr1[3],arr2[3];
int i=3;

if ( (fin = fopen("a.in","r") ) == NULL ) {
printf("\007Cann't open input file a.in ");
exit(0);
};

for (i=0;i<3;i++)
fscanf(fin,"%d %d", &arr1[i], &arr2[i]);

fclose(fin);