原型:extern char *strdup(char *s);
头文件:#include <string.h>
用法:char *strdup(char *s);
功能:复制字符串s 说
明:strdup()在内部调用了malloc()为变量分配内存,当程序结束后,必须用free()释放相应的内存空间,否则会造成内存泄漏
举例:
// strdup.c
#include <syslib.h>
#include <string.h>
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 );