Re: How to create large files with c?



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
.



Relevant Pages

  • Re: How to create large files with c?
    ... My manager told me to create a large file of 2GB ... and the secod 1GB is filled with "World" ... Sorry to say that I don't know how to do that in an elegant way. ... int main ...
    (comp.lang.c)
  • Re: Unsigned integers
    ... >> less efficient (albeit more elegant, of course) than "unrolled loops' ... And I'm with you that small data doesn't always, or even usually, mean fast code. ... Using a short int to save space is going to cost you some speed when the native word size is a long int. ...
    (microsoft.public.vb.syntax)
  • Re: How to Move Two Dialogs at Once
    ... >void CSvg::OnMove(int x, int y) ... you have one dialog that is the "manager" dialog whose position determines the ... Is this a correct characterization? ...
    (microsoft.public.vc.mfc)
  • RE: Trigger to CLR Stored Procedure
    ... Thank you for using Microsoft MSDN Managed Newsgroup Services. ... Create a CLR stored procedure and deploy it to my test database ... DECLARE @math int, @english int, @chinese int ... Please feel free to let my manager ...
    (microsoft.public.sqlserver.mseq)
  • Re: Form Bound to SQL Indexed View
    ... declare @p1 int ... Microsoft Online Community Support ... Please feel free to let my manager ...
    (microsoft.public.access.forms)