Re: How to create large files with c?
- From: David Tiktin <dtiktin@xxxxxxxxxxxxxx>
- Date: Thu, 08 Nov 2007 13:47:50 -0600
On 08 Nov 2007, "Bartc" <bartcasi@xxxxxxxxxxx> wrote:
"loudking" <loudking@xxxxxxxxx> wrote in message
news:1194514413.665505.58820@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello, all
My manager told me to create a large file of 2GB
The first 1GB is filled with "Hello"
and the secod 1GB is filled with "World"
Sorry to say that I don't know how to do that in an elegant way.
Does anybody know how?
Thanks for answering!
The following might do it. Don't know if it's elegant, but it's to
the point:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
FILE* f;
f=fopen("output","wb");
if (f==NULL) return EXIT_FAILURE;
for (i=0; i<214748364; ++i) fprintf(f,"Hello");
fprintf(f,"Hell");
for (i=0; i<214748364; ++i) fprintf(f,"World");
fprintf(f,"Worl");
if (fclose==0) return EXIT_SUCCESS;
fclose is pretty well guaranteed to not be equal to 0 ;-) fclose(f)?
return EXIT_FAILURE;
}
Dave
--
D.a.v.i.d T.i.k.t.i.n
t.i.k.t.i.n [at] a.d.v.a.n.c.e.d.r.e.l.a.y [dot] c.o.m
.
- Follow-Ups:
- Re: How to create large files with c?
- From: Bartc
- Re: How to create large files with c?
- References:
- How to create large files with c?
- From: loudking
- Re: How to create large files with c?
- From: Bartc
- How to create large files with c?
- Prev by Date: Re: getopt under windows
- Next by Date: Re: What's the deal with size_t?
- Previous by thread: Re: How to create large files with c?
- Next by thread: Re: How to create large files with c?
- Index(es):
Relevant Pages
|
|