#include int main(int argc, char **argv) { FILE *fp, *targetfp; char *target; int chr, i; if (argc < 3) { printf("%s \n", argv[0]); puts("not enough args, quitting"); return 1; } /* last argument is treated as target file name */ target = argv[argc-1]; targetfp = fopen(target, "a"); for (i = 1; i < argc - 1; i++) { if ((fp = fopen(argv[i], "r")) == NULL) { printf("could not open file %s, quitting.", argv[i]); fflush(targetfp); fclose(targetfp); return 2; } while ((chr = fgetc(fp)) != EOF) { fputc(chr, targetfp); } fflush(targetfp); fclose(fp); } fclose(targetfp); return 0; }