delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/08/07:27:28

Date: Sun, 8 Mar 1998 14:26:26 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Pieter van Ginkel <pginkel AT westbrabant DOT net>
cc: djgpp AT delorie DOT com
Subject: Re: Copy files.
In-Reply-To: <6dsq61$hb2@news.euro.net>
Message-ID: <Pine.SUN.3.91.980308142603.22686e-100000@is>
MIME-Version: 1.0

On 8 Mar 1998, Pieter van Ginkel wrote:

> I've created this. I know it works because I've tested it, but for some
> weird reason it doesn't work anymore. If I copy a file with the size of e.g.
> 24 K, It copy's a random amount of data. Please help me.
> 
> bool copyfile( char * tofile, char * fromfile )
> {
>   void * buffer = malloc( 1024 );
>   // allocate the maximum amount of characters for buffer
>   size_t haveread, maximumread = 1024;
>   if( !*tofile || !*fromfile ) return false; // one is enty
>   FILE * ffile = fopen( fromfile, "r" );
>   FILE * tfile = fopen( tofile, "w" );

You need to open files in binary mode.  Use "wb" and "rb" in the call
to `fopen'.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019