Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write binary datas in a pipe

Status
Not open for further replies.

cantubas

Programmer
Jan 8, 2004
45
FR
i want to write binary data in a gz file.

i can create file.gz with the popen but i can't write my datas.

printf does't like binary datas like null char


thanks
 
Yes, of course, printf don't like binary data because of it dedicated to print formatted (i.e text) data (but it can write in binary mode too).
Use ANSI/ISO Standard library function fwrite():
Code:
size_t fwrite( const void *buffer, size_t size, size_t count, FILE *stream );
...
char data[100];
... // Write 1st 25 bytes to FILE* stream:
numwritten = fwrite(data, sizeof(char), 25, stream );
...
Don't forget to open a stream on a file (pipe) in binary mode.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top