Create Large File Quickly

Hi,

I am trying to create a large file (5-50 MB) and I am looking for a quick way to do it. I know I can use calloc to allocate large areas in memory, but I'm not sure how to associate that with a file. I think fseek should also do it, but I also want to fill the memory with 0's.

I am making a bastardized file system which will exist as a large file and here is what I am currently doing.
1
2
char * buffer = (char*)calloc(clusterSize*KB, systemSize/clusterSize);
FILE myFile = fopen(name, "w+");
fseek or lseek plus write should do the work. That means after call fseek/lseek to set the file size, you must call write to wirte at least 1 byte at the seeked location, then all file's bytes are 0 except what you write earlier.
It seems fwrite is what I was looking for. Thanks EricDu for the response.

http://cplusplus.com/reference/clibrary/cstdio/fwrite/
Topic archived. No new replies allowed.