Mail Archives: djgpp/1998/03/08/07:27:28
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 -