-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcat.c
More file actions
31 lines (27 loc) · 701 Bytes
/
Copy pathcat.c
File metadata and controls
31 lines (27 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
int main(int argc, char *argv[]){
FILE *fp;
void filecopy(FILE *, FILE *);
char *prog = argv[0];
if(argc == 1)
filecopy(stdin, stdout);
else
while (--argc > 0)
if ((fp = fopen(*++argv, "r")) == NULL){
fprintf(stderr, "%s: can't open %s \n", prog, *argv);
exit(1);
} else {
filecopy(fp, stdout);
fclose(fp);
}
if(ferror(stdout)){
fprintf(stderr, "%s: error writing stdout \n", prog);
exit(2);
}
exit(0);
}
void filecopy(FILE *ifp, FILE *ofp){
int c;
while((c = getc(ifp)) != EOF)
putc(c, ofp);
}