summaryrefslogtreecommitdiffstats
path: root/5/6.c
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2022-01-01 14:28:46 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2022-01-01 14:28:46 +0800
commit87623211e0dbcddb4d6d62b72328c4fca4d11b36 (patch)
tree6c0b3872bd133ed389c097ff6b7f90e1fb68afda /5/6.c
parent08918e3d2fd3aa92111d96fd9bf98ea7ce48adfd (diff)
downloadk&r-exercises-87623211e0dbcddb4d6d62b72328c4fca4d11b36.tar.gz
5.6
Diffstat (limited to '5/6.c')
-rw-r--r--5/6.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/5/6.c b/5/6.c
index 56fe733..d33af6c 100644
--- a/5/6.c
+++ b/5/6.c
@@ -6,7 +6,7 @@ int mgetline(char *s, int lim) {
for (i = 0; i < lim - 1 && (*s++ = getchar()) != EOF && *s != '\n'; i++)
;
-
+
if (*s == EOF)
*s = 0;
else {
@@ -15,4 +15,13 @@ int mgetline(char *s, int lim) {
}
return i;
+}
+
+int matoi(char *s) {
+ int n;
+
+ while (*s >= '0' && *s <= '9')
+ n = 10 * n + (*s++ - '0');
+
+ return n;
} \ No newline at end of file