]> Pileus Git - ~andy/sfvlug/blob - c/src/io.c
Add C notes.
[~andy/sfvlug] / c / src / io.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <errno.h>
4
5 void cat(char *name)
6 {
7         FILE *fd = fopen(name, "r");
8         if (!fd) {
9                 printf("Error opening '%s': %s\n",
10                         name, strerror(errno));
11                 return;
12         }
13
14         int  len = 0;
15         char buf[32] = {};
16         while (!feof(fd)) {
17                 len = fread(buf, 1, sizeof(buf), fd);
18                 printf("{{ Read %d bytes }}", len);
19                 fwrite(buf, 1, len, stdout);
20         }
21
22 }
23
24 int main()
25 {
26         cat("io.c");
27         cat("junk.c");
28         return 0;
29 }