implement cat gnu coreutil

This commit is contained in:
2026-09-26 16:37:17 -07:00
parent 05b2e3b877
commit 2b78d5235a
2 changed files with 37 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
/* TODO:
1. read filename from argv[1]
2. write errors to stderr
3. open file for reading
4. character by character forward to stdout
*/
#include <stdio.h>
#define MAX_LEN 500
int main(int argc, char *argv[]) {
FILE *file;
int c;
fprintf(stderr, "cat <filename>\n");
if (argc != 2) {
fprintf(stderr, "ERROR: invalid input\n");
return -1;
}
file = fopen(argv[1], "r");
if (!file) {
fprintf(stderr, "ERROR: unable to open file\n");
return -1;
}
while ((c = fgetc(file)) != EOF) {
putc(c, stdout);
}
fprintf(stderr, "Completed forward to stdout");
return 0;
}
+1
View File
@@ -0,0 +1 @@
Hello fellas