diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-12-29 19:56:24 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-12-29 19:56:24 +0800 |
| commit | e7242d30471a02d648846c3a63226315126748fc (patch) | |
| tree | aa3e7834093614705acbba1ff08210b97f5aeaed /5 | |
| parent | d92f55ce39a8c516132276673f3128560125b0fe (diff) | |
| download | k&r-exercises-e7242d30471a02d648846c3a63226315126748fc.tar.gz | |
5.3
Diffstat (limited to '5')
| -rw-r--r-- | 5/3.c | 11 |
1 files changed, 5 insertions, 6 deletions
@@ -1,3 +1,4 @@ +#include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -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); |
