fwrite write an integer

Posted by user149100 on Stack Overflow See other posts from Stack Overflow or by user149100
Published on 2010-04-23T03:01:00Z Indexed on 2010/04/23 3:03 UTC
Read the original article Hit count: 352

Filed under:
|
|

I'm trying to write a word to a file using this function:

extern void write_int(FILE * out, int num) {
   fwrite(&num,sizeof(int),1, out);
   if(ferror(out)){
      perror(__func__);
      exit(EXIT_FAILURE);
   }
}

But I get a segmentation fault whenever it tries to run the fwrite. I looked at the man page for fwrite(3) and I feel like I used it correctly, is there something I'm missing?

© Stack Overflow or respective owner

Related posts about c

    Related posts about segmentation-fault