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

本文介绍了C语言中的两个字符串连接函数strcat和strncat,它们分别用于拼接字符串并返回目标字符串的地址。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 的指针。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值