summaryrefslogtreecommitdiffstats
path: root/5
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2022-01-01 14:22:54 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2022-01-01 14:22:54 +0800
commitc290e6d0bb0d65be550fe7ce075ee7cf37678c52 (patch)
treefa54694800013db3a9e5dd699b55fe719c115b9a /5
parent0adbd437bcc5993f441ea1bc68346059e400e817 (diff)
downloadk&r-exercises-c290e6d0bb0d65be550fe7ce075ee7cf37678c52.tar.gz
5.6
Diffstat (limited to '5')
-rw-r--r--5/6.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/5/6.c b/5/6.c
new file mode 100644
index 0000000..bd30014
--- /dev/null
+++ b/5/6.c
@@ -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