strdup函数
函数原型:extern char *strdup(char *str)
参数说明:str待复制的字符串。
        
所在库名:#include <string.h>
  
函数功能:实现复制字符串str。
  
返回说明:返回复制的新字符串的指针,复制失败返回NULL。
其它说明:暂时无。
实例:
 #include <string.h>
#include <string.h> #include <stdio.h>
#include <stdio.h> int main()
int main() {
{ char *str="sky2098,persist in doing again!";
    char *str="sky2098,persist in doing again!";   char *strtemp;
    char *strtemp;  strtemp=strdup(str);   //复制字符串str,复制完成后返回字符串的指针保存在strtemp中
    strtemp=strdup(str);   //复制字符串str,复制完成后返回字符串的指针保存在strtemp中 printf("The string strtemp duplicated from str is:
  %s  ", strtemp);
    printf("The string strtemp duplicated from str is:
  %s  ", strtemp); return 0;
    return 0; }
}在VC++ 6.0编译运行:
复制字符串str成功。
Keep it simple!
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号