From: "J. L." Newsgroups: comp.os.msdos.djgpp Subject: Re: Files fread() in and fread() out get garbled Date: Thu, 05 Dec 2002 17:53:44 -0600 Lines: 45 Message-ID: References: NNTP-Posting-Host: 200.34.143.17 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1039132462 30678250 200.34.143.17 (16 [143309]) X-Newsreader: Forte Agent 1.92/32.572 trialware To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Thu, 5 Dec 2002 22:33:00 -0000, "Eric" wrote: > >Hello. I've been staring at my program for an hour and can't find the bug. >Hope you can help :-) > >My code is supposed to break up a large file into several small files for >transfer on floppy disks, then re-assemble the large file from the parts >given the -r command. Trouble is, the re-assembled file, although the right >size, is messed up in some way: whenever I split a large .exe, for example, >re-assemble it and then run it, all sorts of weirdness occurs. > >PS: I'm a newbie and this is my most ambitious program ever, so please go >easy :-) > [snip code] I see this message also in clc. There are 1 useful advice from Jim about your split function. [snipet reproduced from clc] >> unit = FLOPPY_CAPACITY; >> > { char *tbuffer = buffer; >> while (size) { >> *fname = *name++; >> f = fopen(fname, "wb"); >> if (f == NULL) { >> error(FILE_IO); >> } >> puts("Writing..."); >> - bytes = fwrite(buffer, 1, unit, f); + bytes = fwrite(tbuffer, 1, unit, f) + tbuffer += FLOPPY_CAPACITY; You are allways writing to yours *n* diskettes the same first FLOPPY_CAPACITY bytes of file to split. Change the code acording Jim's advice. J. L.