diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-12-29 19:30:16 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-12-29 19:30:16 +0800 |
| commit | 8b6a64b3efae6b3f1e2bc9cdada1c3764f7eda83 (patch) | |
| tree | dda9e4b4e398d9f90f54691a3572acf2da631368 /5/3.c | |
| parent | bbfec50dc1ee109b6980605eb0d19e6a4641968a (diff) | |
| download | k&r-exercises-8b6a64b3efae6b3f1e2bc9cdada1c3764f7eda83.tar.gz | |
5.3
Diffstat (limited to '5/3.c')
| -rw-r--r-- | 5/3.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -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 |
