diff options
Diffstat (limited to 'usr.bin/learn/lib/C/getline.c')
-rw-r--r-- | usr.bin/learn/lib/C/getline.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/usr.bin/learn/lib/C/getline.c b/usr.bin/learn/lib/C/getline.c new file mode 100644 index 00000000000..8d24aa2b783 --- /dev/null +++ b/usr.bin/learn/lib/C/getline.c @@ -0,0 +1,16 @@ +#include <stdio.h> + +getline(s, lim) /* get line into s, return length */ +char s[]; +int lim; +{ + int c, i; + + i = 0; + while (--lim > 0 && (c=getchar()) != EOF && c != '\n') + s[i++] = c; + if (c == '\n') + s[i++] = c; + s[i] = '\0'; + return(i); +} |