strdup函数

函数原型:extern char *strdup(char *str)

参数说明:str待复制的字符串。
        
所在库名:#include <string.h>
  
函数功能:实现复制字符串str。
  
返回说明:返回复制的新字符串的指针,复制失败返回NULL。

其它说明:暂时无。

实例:

#include <string.h>
#include 
<stdio.h>
int main()
{
    
char *str="sky2098,persist in doing again!";  
    
char *strtemp; 
    strtemp
=strdup(str);   //复制字符串str,复制完成后返回字符串的指针保存在strtemp中
    printf("The string strtemp duplicated from str is:  %s  ", strtemp);
    
return 0;
}

 在VC++ 6.0编译运行:

复制字符串str成功。

原文地址:https://www.cnblogs.com/lgh1992314/p/5835370.html