词条 | strdup |
释义 | 原型: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 ); |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。