I've got a program to do some simple calculations which runs into some errors when I try to make an array too large. The problem is that "too large" isn't very large at all. I've stripped it down to something which replicates the error but doesn't do much else:
#include <stdio.h>
#define SIZE 301
int main(int argc, char *argv[])
{
int i;
int j;
double E[SIZE][SIZE];
FILE *outputfile;
outputfile = fopen("output.txt", "w");
for(j = 0; j < SIZE; j++)
{
for(i = 0; i < SIZE; i++)
{
E[j]=i*j;
fprintf(outputfile,"%f\t",E[j]);
}
fprintf(outputfile,"\n");
}
fclose(outputfile);
return 0;
}
I'm compiling and running this as a simple console program under Windows XP, using Pelles C 6.00.4. If I make SIZE too big (401 is too big), then the program crashes, and I've got no idea why. If SIZE is small (301 is small enough), the program runs fine, and I can even do more complicated calculations with the array that I've cut out for the sake of simplicity. This has the feel of one of those problems which should be easy to solve, if only I knew the key to it, but I don't, and can't make any headway. Any ideas? Am I running up against some DOS memory limit or something? Is there a simple way around it? Any help would be appreciated.