summaryrefslogtreecommitdiffstats
path: root/5
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-12-29 19:56:24 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-12-29 19:56:24 +0800
commite7242d30471a02d648846c3a63226315126748fc (patch)
treeaa3e7834093614705acbba1ff08210b97f5aeaed /5
parentd92f55ce39a8c516132276673f3128560125b0fe (diff)
downloadk&r-exercises-e7242d30471a02d648846c3a63226315126748fc.tar.gz
5.3
Diffstat (limited to '5')
-rw-r--r--5/3.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/5/3.c b/5/3.c
index 8347c38..dd9c3e4 100644
--- a/5/3.c
+++ b/5/3.c
@@ -1,3 +1,4 @@
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -8,18 +9,16 @@ void mstrcat(char *, char *);
int main(int argc, char *argv[]) {
char *s, *t;
- size_t n;
- s = malloc(MAXLEN);
- t = malloc(MAXLEN);
- n = sizeof(s);
+ s = malloc(sizeof(char) * MAXLEN);
+ t = malloc(sizeof(char) * MAXLEN);
printf("first str: ");
- getline(&s, &n, stdin);
+ fgets(s, MAXLEN, stdin);
s[strlen(s) - 1] = 0;
printf("second str: ");
- getline(&t, &n, stdin);
+ fgets(t, MAXLEN, stdin);
t[strlen(t) - 1] = 0;
mstrcat(s, t);