strdup
来源:互联网 发布:男士减肥健身计划 知乎 编辑:程序博客网 时间:2024/05/17 02:26
strdup
编辑
本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧!
strdup()函数是c语言中常用的一种字符串拷贝库函数,一般和free()函数成对出现。
- strdup
- string.h
- 将串拷贝到新建的位置处
- 字符串拷贝库函数
目录
原型:编辑
extern char *strdup(char *s);
头文件:string.h
说明:编辑
功 能: 将串拷贝到新建的位置处
strdup()在内部调用了malloc()为变量分配内存,不需要使用返回的字符串时,需要用free()释放相应的内存空间,否则会造成内存泄漏。
返回值:编辑
返回一个指针,指向为复制字符串分配的空间;如果分配空间失败,则返回NULL值。
Example:编辑
①.// strdup.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
int main()
{
char *s="Golden Global View";
char *d;
clrscr();
d=strdup(s);
if(NULL != d) {
printf("%s\n",d);
free(d);
}
getchar();
return 0;
}
运行结果:
Golden Global View
②.Example:
CString sPath="d:\\1.jpg";
LPTSTR str = strdup( sPath );
0 0
- strdup
- strdup
- strdup
- strdup
- strdup
- strdup
- strdup
- strdup
- strdup
- strdup
- strdup
- strdup
- strdup
- strdup
- strdup()
- strdup
- strdup
- strdup函数
- ServerU FTP 9.1.0.5完美破解版 使用教程 学校局域网上课上传下载文件用--图片来自网络
- zookeeper(五)java API
- 网络连接评分机制之NetworkAgent(原)
- 学习规划——半年
- 【LeetCode】Lowest Common Ancestor of a Binary Search Tree
- strdup
- 数据结构
- Java中字符串switch的实现细节
- 安卓5.0 以上移动网络耗电异常解决方法
- 执行数据库操作失败: 连接未关闭。 连接的当前状态为打开
- 基于Maven的Spring + Spring MVC + Mybatis的环境搭建
- ocp-191
- 字符串的正则表达式
- ocp-192