28 lines
523 B
C
28 lines
523 B
C
#include <stdio.h>
|
|
|
|
void filecopy(FILE *, FILE *);
|
|
|
|
int main(int argc, char *argv[]) {
|
|
FILE *file_p;
|
|
|
|
if (argc == 1)
|
|
filecopy(stdin, stdout);
|
|
else
|
|
while (--argc > 0)
|
|
if ((file_p = fopen(*++argv, "r")) == NULL) {
|
|
printf("cat: can't open: %s\n", *argv);
|
|
return 1;
|
|
} else {
|
|
filecopy(file_p, stdout);
|
|
fclose(file_p);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void filecopy(FILE* in_file_p, FILE* out_file_p) {
|
|
int ch;
|
|
|
|
while((ch = getc(in_file_p)) != EOF)
|
|
putc(ch, out_file_p);
|
|
}
|