C 语言的 strcat() 函数和 strncat() 函数

strcat() 函数

原型: char *strcat(char *dest, const char *src)

参数:

dest – 指向目标数组,该数组包含了一个 C 字符串,且足够容纳追加后的字符串。

src – 指向要追加的字符串,该字符串不会覆盖目标字符串。

返回值: 该函数返回一个指向最终的目标字符串 dest 的指针。

头文件: <string.h>

The strcat() (for string concatenation ) function takes two strings for arguments. A copy of the second string is tacked onto the end of the first, and this combined version becomes the new first string. The second string is not altered. The strcat() function is type char * (that is, a pointer-to- char ). It returns the value of its first argument—the address of the first character of the string to which the second string is appended.

strncat() 函数

头文件: <string.h>

char *strncat(char *dest, const char *src, size_t n)

参数

dest – 指向目标数组,该数组包含了一个 C 字符串,且足够容纳追加后的字符串,包括额外的空字符。

src – 要追加的字符串。

n – 要追加的最大字符数。

把 src 所指向的字符串追加到 dest 所指向的字符串的结尾,直到 n 字符长度为止。

返回值: 该函数返回一个指向最终的目标字符串 dest 的指针。

猜你喜欢

转载自blog.csdn.net/chengkai730/article/details/132396797