I need to write data to a binary file using C's I/O functions. The following code causes a runtime exception :
#include "stdio.h"
int main(int argc,char* argv[]) {
FILE *fp = fopen("path_to_file.bin","wb");
if(fp == NULL) {
printf("error creating file");
return -1;
}
int val = 4;
fwrite((const void*)val,sizeof(int),1,fp);
fclose(fp);
return 0;
}
The code dies at the fwrite. Can you spot what I'm doing wrong? Apparently, I'm, trying to access data at 0x0000004 or something like that.
Thanks !