遇见YY

导航

 
#include <string.h>
char *strdup(const char *s);

description:

strdup()函数返回一个指向新字符串的指针,该字符串与s字符串副本。 新字符串的内存是通过malloc获得的,可以通过free释放。

return value:

返回值成功时,strdup()函数将返回指向副本字符串的指针。 如果没有足够的可用内存,它将返回NULL,并设置errno来指示错误原因。

#include <stdio.h>
#include <string.h>
int main(void)
{
     char *src ="This is the strdup test!";
     char *des;
     des = strdup(src);
     printf("dest: %s\n",des);
    free(des);
     return 0;

}

 

posted on 2020-08-12 21:07  一骑红尘妃子笑!  阅读(224)  评论(0编辑  收藏  举报