-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcat.c
More file actions
26 lines (24 loc) · 678 Bytes
/
Copy pathcat.c
File metadata and controls
26 lines (24 loc) · 678 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
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
enum { buf_max = 32, };
int main(int argc, char* argv[argc+1]) {
int ret = EXIT_FAILURE;
char buffer[buf_max] = { 0 };
for (int i = 1; i < argc; ++i) { // Processes args
FILE* instream = fopen(argv[i], "r"); // as filenames
if (instream) {
while (fgets(buffer, buf_max, instream)) {
fputs(buffer, stdout);
}
fclose(instream);
ret = EXIT_SUCCESS;
} else {
/* Provides some error diagnostic. */
fprintf(stderr, "Could not open %s: ", argv[i]);
perror(0);
errno = 0; // Resets the error code
}
}
return ret;
}