diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2022-01-01 14:22:54 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2022-01-01 14:22:54 +0800 |
| commit | c290e6d0bb0d65be550fe7ce075ee7cf37678c52 (patch) | |
| tree | fa54694800013db3a9e5dd699b55fe719c115b9a /5 | |
| parent | 0adbd437bcc5993f441ea1bc68346059e400e817 (diff) | |
| download | k&r-exercises-c290e6d0bb0d65be550fe7ce075ee7cf37678c52.tar.gz | |
5.6
Diffstat (limited to '5')
| -rw-r--r-- | 5/6.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -0,0 +1,18 @@ +#include <stdio.h> +#include <stdlib.h> + +int mgetline(char *s, int lim); + +int mgetline(char *s, int lim) { + int i; + + for (i = 0; i < lim - 1 && (*s++ = getchar()) != EOF && *s != '\n'; i++) + ; + + if (*s == EOF) + *s = 0; + else + *++s = 0; + + return i; +}
\ No newline at end of file |
