From 8b6a64b3efae6b3f1e2bc9cdada1c3764f7eda83 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Wed, 29 Dec 2021 19:30:16 +0800 Subject: 5.3 --- 5/3.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to '5') diff --git a/5/3.c b/5/3.c index fe839a4..6db86b5 100644 --- a/5/3.c +++ b/5/3.c @@ -1,6 +1,7 @@ #include #include #include +#include #define MAXLEN 1000 @@ -16,9 +17,11 @@ int main(int argc, char *argv[]) { printf("first str: "); getline(&s, &n, stdin); + s[strlen(s) - 1] = 0; printf("second str: "); getline(&t, &n, stdin); + t[strlen(t) - 1] = 0; mstrcat(s, t); printf("strcat: %s\n", s); @@ -31,7 +34,6 @@ void mstrcat(char *s, char *t) { for (i = 0; i < MAXLEN - 1 && *s++; i++) ; - for (s -= 2; i < MAXLEN - 1 && (*s++ = *t++) != '\n'; i++) + for (s--; i < MAXLEN - 1 && (*s++ = *t++); i++) ; - *s = 0; } \ No newline at end of file -- cgit v1.2.3