下面列出的文件中包含将这些数字插入两个单独的数组的代码:
18 18 25 31 37 82 82 87 89 230 85 87 558
and
3 3 3 3 3 3 5 4 4 4 10 3 3 10
Neither work and the outputs are gigantic, examples being 2686616268663241991898240010027008-3520000390268663219918982491991898624
Anyone able to help fix this?Sorry this is just inside main it has suitable includes and main{}
FILE *locFile;
LOCFile = fopen("c:\\locvalues.txt", "r");
FILE *methodFile;
methodFile = fopen("c:\\methodvalues.txt", "r");
int locArray[13];
int methodArray[13];
int i;
for (i = 0; i < 13; i++)
{
fscanf(locFile, "%d", &locArray[i]);
fscanf(methodFile, "%d", &methodArray[i]);
}
for (i = 0; i < 13; i++)
{
printf("%d\n", locArray[i]);
printf("%d\n", methodArray[i]);
}
fclose(locFile);
fclose(methodFile);
最佳答案
如注释中所示,如果在第二行用LOCFile
替换locFile
并重新编译,则示例代码应运行良好。
关于c - 将数字从文件扫描到数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30365593/