函数原型: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!