]> Pileus Git - ~andy/sfvlug/blobdiff - c/src/io.c
Add C notes.
[~andy/sfvlug] / c / src / io.c
diff --git a/c/src/io.c b/c/src/io.c
new file mode 100644 (file)
index 0000000..89666ab
--- /dev/null
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+void cat(char *name)
+{
+       FILE *fd = fopen(name, "r");
+       if (!fd) {
+               printf("Error opening '%s': %s\n",
+                       name, strerror(errno));
+               return;
+       }
+
+       int  len = 0;
+       char buf[32] = {};
+       while (!feof(fd)) {
+               len = fread(buf, 1, sizeof(buf), fd);
+               printf("{{ Read %d bytes }}", len);
+               fwrite(buf, 1, len, stdout);
+       }
+
+}
+
+int main()
+{
+       cat("io.c");
+       cat("junk.c");
+       return 0;
+}