36 lines
692 B
C
Executable file
36 lines
692 B
C
Executable file
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main(int argc, char *argv[]) {
|
|
FILE * in_file;
|
|
int i, error = 0;
|
|
char c;
|
|
|
|
if(argc == 1) {
|
|
in_file = stdin;
|
|
for(c = fgetc(in_file); c != EOF; c = fgetc(in_file)) {
|
|
fprintf(stdout, "%c", c);
|
|
}
|
|
}
|
|
|
|
for(i = 1; i < argc; i++) {
|
|
if(argv[i][0] == '-' && argv[i][1] == '\0')
|
|
in_file = stdin;
|
|
else {
|
|
in_file = fopen(argv[i], "r");
|
|
if(in_file == NULL) {
|
|
fprintf(stderr, "Cannot find file %s\n", argv[i]);
|
|
error = 1;
|
|
continue;
|
|
}
|
|
}
|
|
for(c = fgetc(in_file); c != EOF; c = fgetc(in_file))
|
|
fprintf(stdout, "%c", c);
|
|
}
|
|
|
|
if(error)
|
|
return 1;
|
|
else
|
|
return 0;
|
|
}
|