Write a binary file containing zeros to a Linux file system

Clash Royale CLAN TAG#URR8PPPWrite a binary file containing zeros to a Linux file system
I have a large block of memory in my C program that contains zeros in the middle. I want to save this to disk without converting the values to ASCII. Will writing zeros to a file stream cause a false-negative EOF when I try to read from that file later?
Example:
int x[1024] = {1, 2, 3, 4, 0, 0, 0, 0, 3};
// write x to disk in myfile.bin
Thanks in advance!
fwrite
0
0x1A
1 Answer
1
Null bytes in a file don't trigger EOF, even on text files. Hitting EOF is something the I/O libraries are able to detect regardless of content.
As long as you use write or fwrite to write the memory block to disk and later use read or fread to read it, you should be fine.
write
fwrite
read
fread
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Not if you use
fwriteto write the memory block to a binary file. Next,0is not an EOF indicator. Except in some old text file formats (which used0x1A), there is no EOF indicator present as part of the file.– Weather Vane
6 mins ago