blob: fe839a425f1e935c93a0ae152674060be319d9b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#define MAXLEN 1000
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);
printf("first str: ");
getline(&s, &n, stdin);
printf("second str: ");
getline(&t, &n, stdin);
mstrcat(s, t);
printf("strcat: %s\n", s);
return 0;
}
void mstrcat(char *s, char *t) {
int i;
for (i = 0; i < MAXLEN - 1 && *s++; i++)
;
for (s -= 2; i < MAXLEN - 1 && (*s++ = *t++) != '\n'; i++)
;
*s = 0;
}
|