Path: utzoo!attcan!uunet!zephyr.ens.tek.com!tekcrl!tekgvs!toma From: toma@tekgvs.LABS.TEK.COM (Tom Almy) Newsgroups: comp.sys.ibm.pc Subject: Re: File concatenation using Microsoft C under MS-DOS? Message-ID: <7641@tekgvs.LABS.TEK.COM> Date: 11 Jun 90 15:24:10 GMT References: <4891@druco.ATT.COM> Reply-To: toma@tekgvs.LABS.TEK.COM (Tom Almy) Organization: Tektronix, Inc., Beaverton, OR. Lines: 32 [The question was how to concatenate files in the fastest manner]. Assuming you want to use stdio calls (using open, read, and write would be fastest) do this FILE *infile, *outfile; #define BUFSIZE 32768 /* or some other large multiple of 512 */ char *cbuf; int count; infile = fopen(sourceFileName,"rb"); /* open in binary mode */ outfile = fopen(concatFileName,"ab"); /* same for destination file */ setbuf(infile,NULL); /* Do your own buffering */ setbuf(outfile,NULL); cbuf = malloc(BUFSIZE); while ((count = fread(cbuf,sizeof(char),BUFSIZE,infile)) > 0) fwrite(cbuf,sizeof(char),count,outfile); free(cbuf); fclose(infile); fclose(outfile); It is important to both specify binary mode (to eliminate the crlf <-> \n translation) and to use a large buffer, which is in turn better done by yourself so a single buffer can be used. Tom Almy toma@tekgvs.labs.tek.com Standard Disclaimers Apply