原型:extern char *strdup(char *s);
头文件:#include <string.h>
用法:char *strdup(char *s);
功能:复制字符串s
说明:strdup()在内部调用了malloc()为
变量
分配内存,当程序结束后,必须用free()释放相应的内存空间,否则会造成内存泄漏
举例:
// strdup.c
//#include <syslib.h>
#include <stdio.h>
#include <string.h>
int main()
{
char *s="Golden Global View";
char *d;
clrscr();
d=strdup(s);
printf("%s",d);
free(d);
getchar();
return 0;
}
例
CString sPath="d:\\1.jpg";
LPTSTR str = strdup( sPath );
strdup的用法
最新推荐文章于 2025-02-22 11:34:25 发布