c - How to write 0x00 into file -
i'm writing application communicate (write only) custom usb-serial device. cocoa (os x) application , part related writing coded in posix style.
i have solved things have issues null (0x00) character.
for example lets says need white 5 characters file.
my code follow:
char stringaschar[5]; stringaschar[0] = 0x77; stringaschar[1] = 0x44; stringaschar[2] = 0x00; //here problem stringaschar[3] = 0x05; stringaschar[4] = 0xff; ... fputs(stringaschar, file); // write file
each character @ specified index represents data registers target device.
the problem arise when stream include 0x00 character need have data, writing stopped there (0x00 interpreted stop of stream).
how overcome issue?
fputs
works nul
-terminated strings. if want write nul
characters file can use fwrite
instead:
noofbyteswritten = fwrite(stringaschar, 1, noofbytestowrite, file);
Comments
Post a Comment