Here is the source code:
int main() {
int secondsInYear = 366*24*60*60; // Equals 31,622,400
short int data[secondsInYear];
FILE * pFile;
pFile = fopen ("stat", "r");
fread(data, sizeof(short int), secondsInYear, pFile);
fclose(pFile);
}
on line fopen("stat", "r") it gives me the segmentation fault error! If I read secondsInYear/10 characters it will execute without any problem, So what seems to be the problem? And what’s the solution?
You’re creating a massive array on the stack. So you are hitting a stackoverflow. 🙂
You should dynamically allocate that array instead.
and be sure to delete it later: