summaryrefslogtreecommitdiffstats
path: root/5/3.c
diff options
context:
space:
mode:
Diffstat (limited to '5/3.c')
-rw-r--r--5/3.c6
1 files changed, 4 insertions, 2 deletions
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 <stddef.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#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