Dear all,
I ran into the following weird problem while trying to write a simple C program using structures. The source is as follows
Code:
#include <stdio.h>
#include <stdlib.h>
struct filerectype {
char myarray [9];
};
int main()
{
FILE *fp;
fp = fopen("file.txt", "rt");
if (!fp) {
printf("fopen error\n");
exit(-1);
}
char* line;
struct filerectype filerec;
while( !feof(fp) ) {
if ( fgets (line, 100, fp) != NULL)
puts (line);
}
fclose(fp);
exit(0);
} //main()
The source compiles without problems but when I try to run the .exe file, it freezes and pops the error window "blah.exe has stopped working"
Now the weird part is, that in case I play around with the fields of struct filerectype, then the .exe runs without any problems and outputs the content of file.txt. But this is all nondeterministic, i.e. when I started to write this comment, then I wanted to illustrate with an example that it works correctly with myarray size 8 and freezes with myarray size 9, but since then I played arround with the struct fields a bit again and now it freezes with myarray size 3
I am actually using Win7 and Bloodshed 4.9.9.2 if that has any relevance, but I rather suspect that it is some coding problem which I was not able to figure out so far. The goal would be actually to write a simple program using dynamic struct chains built from the data read from the file, and I have the whole concept designed on skeleton level, but this problem is now completely blocking the coding
Thank you for any help in advance