So while running this code I keep getting the error:
“/Applications/TextMate.app/Contents/SharedSupport/Bundles/C.tmbundle/Support/bin/bootstrap.sh: line 7: 11441 Bus error: 10 “$3″.out”
I looked through previous posts but couldn’t figure it out, does anyone have an idea why this would be happening. Ive seen posts saying it is because of the arrays being too large for memory but i can’t imagine 2 20space int arrays are that big.
#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 looks like:
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
fscanfreturns the number of of items successfully read, I think you want to test ifnumber == 0to break from the loop.