diff options
Diffstat (limited to 'c/head.c')
| -rw-r--r-- | c/head.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/c/head.c b/c/head.c new file mode 100644 index 0000000..9363b1c --- /dev/null +++ b/c/head.c @@ -0,0 +1,16 @@ +#include "gbos.h" +/* head [n]: print the first n lines of stdin (default 10). Drains the rest to + EOF so the shell sees a clean end of input. */ +void main(void) { + char *a = getargs(); + unsigned char n = 10; + unsigned char lines = 0; + char c; + if (*a) n = atou(a); + for (;;) { + c = readc(); + if (c == EOF) break; + if (lines < n) putc(c); + if (c == '\n') lines++; + } +} |
