strcat 库函数用于连接两个字符串,目的字符串要有足够大的空间存放连接后的字符串。
- #include <stdio.h>
-
-
char *strcat_test(char *dest, const char *src);
-
-
int
-
main(int argc, char **argv)
-
{
-
char d[20] = {'h','e','l','l','o',' '};
-
char *s = "world";
-
-
strcat_test(d, s);
-
-
printf("Result: %s\n", d);
-
-
return 0;
-
}
-
-
char
-
*strcat_test(char *dest, const char *src)
-
{
-
char *tmp = dest;
-
-
while (*dest) {
-
dest++;
-
}
-
while ((*dest++ = *src++) != '\0') {
-
; /* nothing */
-
}
-
-
return tmp;
-
}
阅读(344) | 评论(0) | 转发(0) |