C Segmentation fault - saving struct in .dat file
问题 Can someone please tell me, what causes the segementation fault in my C - code? I am trying to save a struct into a file, and calling it afterwards, following this guide. I don't see anything assigned wrongly, so I'm happy to learn what's my mistake by someone more experienced. Here is my code, simplified: int main(int argc, char **argv) { char *key = (argc > 4) ? argv[4]: 0; if(0==strcmp(key, "write")){ struct MyStruct s; FILE *myoutfile; myoutfile = fopen("file.dat","w") if (myoutfile ==