What is the most efficient quickest way to write all zeros to a file? including error checking. Would it just be fwrite? or is fseek involved?
I’ve looked elsewhere and saw code similar to this:
off_t size = fseek(pFile,0,SEEK_END);
fseek(pFile,0,SEEK_SET);
while (size>sizeof zeros)
size -= fwrite(&address, 1, sizeof zeros, pFile);
while (size)
size -= fwrite(&address, 1, size, pFile);
where zeros is an array of file size I suspect. Not sure exactly what off_t was because it wasn’t directly intuitive to me anyways
Do you want to replace the contents of the file with a stream of binary zeroes of the same length, or do you want to simply empty the file? (make it have length zero)
Either way, this is best done with the OS file I/O primitives. Option one:
Option two:
Error handling left as an exercise.