summaryrefslogtreecommitdiffstats
path: root/5
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-12-29 19:30:16 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-12-29 19:30:16 +0800
commit8b6a64b3efae6b3f1e2bc9cdada1c3764f7eda83 (patch)
treedda9e4b4e398d9f90f54691a3572acf2da631368 /5
parentbbfec50dc1ee109b6980605eb0d19e6a4641968a (diff)
downloadk&r-exercises-8b6a64b3efae6b3f1e2bc9cdada1c3764f7eda83.tar.gz
5.3
Diffstat (limited to '5')
-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