aboutsummaryrefslogtreecommitdiffstats
path: root/cat.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cat.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/cat.c b/cat.c
new file mode 100644
index 0000000..74121b7
--- /dev/null
+++ b/cat.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+ FILE *f;
+ char c;
+
+ for (int i = 1; i < argc; i++) {
+ f = fopen(argv[i], "r");
+
+ if (f == NULL) {
+ fprintf(stderr, "Cannot read input file \"%s\"\n", argv[i]);
+ return 1;
+ }
+
+ do {
+ c = fgetc(f);
+ printf("%c", c);
+ } while (c != EOF);
+ fclose(f);
+ }
+}