os/kolos/main.c

43 lines
840 B
C
Raw Permalink Normal View History

2019-06-14 20:04:43 +02:00
#include <stdio.h>
int main(int argc, char **argv)
{
FILE *fp, *targetfp;
char *target;
int chr, i;
if (argc < 3)
{
printf("%s <file1> <fileN...> <file to copy to>\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;
}