#include #include #include #include /* This program reads the files whose naems are specified on the command line, concatenates them, and writes the result to `merged.dat'. Can be used instead of `cat', or `copy /b ... + ... + ...' */ typedef char * str; typedef int logical; #define oops(s) { fprintf(stderr, "%s\n", s); exit(1); } const int LB=16384; int main(int argc, str argv[]) { FILE *f, *g; char *buffer; char *p, *outname = "merged.dat"; int d, i; if (argc < 2) { printf("Use:\n"); printf("\t%s ...\n", argv[0]); printf("to concatenate the files and write the output to `%s'\n", outname); exit(0); } buffer = (char*)malloc(LB); if (!buffer) oops("Out of memory!"); if (access(outname, 0) == 0) { fprintf(stderr, "File %s already exists. Please remove it first\n", outname); exit(1); } g = fopen(outname, "wb"); if (!g) { fprintf(stderr, "Can't write to the file `%s'\n", outname); exit(1); } for(i=1; i0) fwrite( buffer,1, d, g); fclose(f); } return 0; }