B
Billy Mays
I'm trying to preallocate a file for later writing, and I have a small
segment of code that does it:
/***************************************/
#include <stdio.h>
int main(int argc, char ** argv)
{
FILE * f;
char zero = 0;
f = fopen("test.bin", "wb");
fseek(f, (1<<20) - 1, SEEK_SET);
fwrite(&zero, sizeof(char), 1, f);
fclose(f);
return 0;
}
/***************************************/
Is this the correct approach? Can I guarantee that the space that is
skipped over with always be zero bytes ('\0') ? Is this portable or
even specified in the C standard?
segment of code that does it:
/***************************************/
#include <stdio.h>
int main(int argc, char ** argv)
{
FILE * f;
char zero = 0;
f = fopen("test.bin", "wb");
fseek(f, (1<<20) - 1, SEEK_SET);
fwrite(&zero, sizeof(char), 1, f);
fclose(f);
return 0;
}
/***************************************/
Is this the correct approach? Can I guarantee that the space that is
skipped over with always be zero bytes ('\0') ? Is this portable or
even specified in the C standard?