OLD | NEW |
---|---|
(Empty) | |
1 #include <stdio.h> | |
2 #include <string.h> | |
3 #include <unistd.h> | |
4 | |
5 void write_int_(int fd, int n) { | |
6 if (n > 0) { | |
7 write_int_(fd, n / 10); | |
8 | |
9 int rem = n % 10; | |
10 char c = '0' + rem; | |
11 write(fd, &c, 1); | |
12 } | |
13 } | |
14 | |
15 void write_int(int fd, int n) { | |
16 if (n == 0) { | |
17 write(fd, "0", 1); | |
18 } else { | |
19 if (n < 0) { | |
20 write(fd, "-", 1); | |
21 write_int_(fd, -n); | |
22 } else { | |
23 write_int_(fd, n); | |
24 } | |
25 } | |
26 } | |
27 | |
28 void stderr_int(int n) { | |
29 write_int(2, n); | |
30 write(2, "\n", 1); | |
31 } | |
32 | |
33 int main(int argc, const char **argv) { | |
34 char *str = "Hello, World!\n"; | |
35 for (int i = 0; str[i]; ++i) { | |
36 putchar(str[i]); | |
37 | |
38 // write(2, "---\n", 4); | |
Jim Stichnoth
2016/04/14 20:03:44
Do these commented lines need to stay?
Eric Holk
2016/04/15 15:24:27
Nope.
Done.
| |
39 // write(2, "wpos: ", 6); | |
40 // stderr_int(((int *)stdout)[5]); //wpos | |
41 // write(2, "wend: ", 6); | |
42 // stderr_int(((int *)stdout)[4]); //wend | |
43 } | |
44 return 0; | |
45 } | |
OLD | NEW |