函数原型:extern char *strdup(char *str)
参数说明:str待复制的字符串。
所在库名:#include <string.h>
函数功能:实现复制字符串str。
返回说明:返回复制的新字符串的指针,复制失败返回NULL。
例子:
#include <string.h>
#include <stdio.h>
int main()
{
char *s = "I come from BUAA!";
char *strtemp;
strtemp = strdup(s);
printf("The string duplicated from s is: %s\n", strtemp);
return 0;
}
输出为:
The string duplicated from s is: I come from BUAA!
strdup函数详解
本文介绍了字符串复制函数strdup的功能及用法。该函数用于复制指定的字符串,并返回新分配内存中字符串的指针。文章通过示例展示了如何使用strdup进行字符串复制。
6万+

被折叠的 条评论
为什么被折叠?



