From e7242d30471a02d648846c3a63226315126748fc Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Wed, 29 Dec 2021 19:56:24 +0800 Subject: 5.3 --- 5/3.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to '5') 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 #include #include #include @@ -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); -- cgit v1.2.3