I need to write a string that might contain null characters to a file. However, C's strings are terminated by a null character. How do I do that?
I need to write a string that might contain null characters to a file. However, C's strings are terminated by a null character. How do I do that?
Open the file in Binary mode, and don't use string-based write routines.
Mainframe assembler programmer by trade. C coder when I can.
For most I/O routines, you have to indicate the number of bytes you wish to use instead of relying of the null char as an end marker (e.g. fread/fwrite() or simply read/write()).
Thanks. I now use fputc() instead of fputs().
And thanks for the quick responses!