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
fwrite((const void*)val,sizeof(int),1,fp);
should be:
fwrite((const void*) & val,sizeof(int),1,fp);
BTW, if you don't use the cast, you will get a sensible error message. Casts tend to be used by C (and C++) programmers far more often than they should be - a good rule of thumb is "if it needs a cast, it's probably wrong".