diff --git a/coreutils/cat.c b/coreutils/cat.c new file mode 100644 index 0000000..028af9f --- /dev/null +++ b/coreutils/cat.c @@ -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 + +#define MAX_LEN 500 + +int main(int argc, char *argv[]) { + FILE *file; + int c; + + fprintf(stderr, "cat \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; +} diff --git a/coreutils/note.txt b/coreutils/note.txt new file mode 100644 index 0000000..1b83a36 --- /dev/null +++ b/coreutils/note.txt @@ -0,0 +1 @@ +Hello fellas