blob: 3a4a2a6f22e6b0350bc844e4d357b0323b5bb904 (
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
38
39
40
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLEN 1000
/* Copies str t to the end of str s */
void mstrcat(char *s, char *t);
int main(int argc, char *argv[]) {
char *s, *t;
s = malloc(sizeof(char) * MAXLEN);
t = malloc(sizeof(char) * MAXLEN);
printf("first str: ");
fgets(s, MAXLEN, stdin);
s[strlen(s) - 1] = 0;
printf("second str: ");
fgets(t, MAXLEN, stdin);
t[strlen(t) - 1] = 0;
mstrcat(s, t);
printf("strcat: %s\n", s);
free(s);
free(t);
return 0;
}
void mstrcat(char *s, char *t) {
int i;
for (i = 0; i < MAXLEN && *s++; i++)
;
for (s--; i < MAXLEN && (*s++ = *t++); i++)
;
}
|