字符串处理函数

//作为标准C/C++ ,这里的函数都是标准库里的函数

1字符串拷贝

(1)char * strcpy(char * dest, const char * src)

   //来自cppreference: http://www.cplusplus.com/reference/clibrary/cstring/strcpy/

功能: 把src指向的字符串拷贝到dest指向的位置,包括'/0'。拷贝回直到src结尾位置。

Copies the C string pointed by source into the array pointed by destination, including the terminating null character.

To avoid overflows, the size of the array pointed by destination shall be long enough to contain the same C string as source (including the terminating null character), and should not overlap in memory with source.

 

(2) char * strncpy( char * dest, const char * src, size_t num)

至多拷贝num个src指向的字符到dest处。 如果直到src的第num个字符都没有遇到'/0',那么就拷贝这num个字符,不会再补充一个'/0'了。如果遇到了'/0‘, 那么就在此位置一直num设置为'/0'

//来自cppreference: http://www.cplusplus.com/reference/clibrary/cstring/strcpy/

Copy characters from string

Copies the first num characters of source to destination. If the end of the source C string (which is signaled by a null-character) is found before num characters have been copied, destination is padded with zeros until a total of num characters have been written to it.

No null-character is implicitly appended to the end of destination, so destination will only be null-terminated if the length of the C string in source is less than num.

Parameters

destination
Pointer to the destination array where the content is to be copied.
source
C string to be copied.
num
Maximum number of characters to be copied from source.


Return Value

destination is returned.

 

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值