I'm trying to make a 2D random array that prints itself out on a document and when I put anything above [1448][1448] the array doesn't work and returns "Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeef3ffff8)" if I put anything below that it works but I don't understand why it doesn't work, I have over a gigabyte of free memory on my mac.
FILE * fdave = fopen("/Users/dave/Documents/dave.txt", "w");
int mapx, mapy, tempx = 0, tempy = 0;
printf("X Length: 0-");
scanf("%d", &mapx);
printf("Y Length: 0-");
scanf("%d", &mapy);
int grid[mapy][mapx];
fprintf(fdave, "{\n");
for (tempy = 0;tempy < (mapy); tempy++){
fprintf(fdave, "{");
for (tempx = 0; tempx < (mapx); tempx++){
grid[tempy][tempx] = rand() % 10;
if (tempx == mapx - 1){
fprintf(fdave, "%d", grid[tempy][tempx]);
}else{
fprintf(fdave, "%d, ", grid[tempy][tempx]);
}
}
if (tempy == mapy - 1){
fprintf(fdave, "}\n");
}else{
fprintf(fdave, "},\n");
}
}
fprintf(fdave, "}\n");
fclose(fdave);