因此,在运行此代码时,我不断收到错误消息:
“/Applications/TextMate.app/Contents/SharedSupport/Bundles/C.tmbundle/Support/bin/bootstrap.sh:第 7 行:11441 总线错误:10“$3”.out”
我浏览了以前的帖子,但无法弄清楚,有没有人知道为什么会发生这种情况。我看过帖子说这是因为数组对于内存来说太大了,但我无法想象 2 20space int 数组有那么大。
#include <stdio.h>
int read_file(int *x, int *y);
int main()
{
int count, x[25], y[25];
count = read_file(x,y);
return 0;
}
int read_file(int *x, int *y)
{
int number, i;
FILE *fp;
fp = fopen("data.txt", "r");
printf("File open");
for(i = 0 ; fscanf(fp, "%d", &number) != 0; i++)
{
x[i] = number;
}
for(i = 0 ; fscanf(fp, "%d", &number) != 0; i++)
{
y[i] = number;
}
fclose(fp);
return (i-1);
}
data.txt 看起来像:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 0