/* p12b.c */ #include #include /* The mission of this function is to catenate */ /* the string pointed to by p2 to the end of */ /* the string pointed to by p1 */ void zstrcat( char *p1, char *p2) { char *src; /* source pointer */ char *dst; /* destination pointer */ dst = p1; src = p2; /* Start by advancing dest to the end */ /* of the string pointed to by p1 */ while (*dst != 0) dst = dst + 1; /* Now tack on the string pointed to by p2 */ while (*src != 0) { *dst = *src; dst = dst + 1; src = src + 1; } *dst = 0; } main() { char *s1; char *s2; char *result; s1 = (char *)malloc(40); s2 = (char *)malloc(40); result = (char *)malloc(81); *result = 0; fgets(s1, 40, stdin); fgets(s2, 40, stdin); zstrcat(result, s1); zstrcat(result, " "); zstrcat(result, s2); fputs(result, stdout); }