博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
strdup用法
阅读量:2187 次
发布时间:2019-05-02

本文共 475 字,大约阅读时间需要 1 分钟。

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 );

转载地址:http://larkb.baihongyu.com/

你可能感兴趣的文章
Windows下使用jsoncpp
查看>>
Ubuntu下测试使用Nginx+uWsgi+Django
查看>>
Windows下编译x264
查看>>
visual studio调试内存泄漏工具
查看>>
开源Faac实现PCM编码AAC
查看>>
Windows下wave API 音频采集
查看>>
借船过河:一个据说能看穿你的人性和欲望的心理测试
查看>>
AndroidStudio 导入三方库使用
查看>>
Ubuntu解决gcc编译报错/usr/bin/ld: cannot find -lstdc++
查看>>
解决Ubuntu14.04 - 16.10版本 cheese摄像头灯亮却黑屏问题
查看>>
解决Ubuntu 64bit下使用交叉编译链提示error while loading shared libraries: libz.so.1
查看>>
Android Studio color和font设置
查看>>
Python 格式化打印json数据(展开状态)
查看>>
Centos7 安装curl(openssl)和libxml2
查看>>
Centos7 离线安装RabbitMQ,并配置集群
查看>>
Centos7 or Other Linux RPM包查询下载
查看>>
运行springboot项目出现:Type javax.xml.bind.JAXBContext not present
查看>>
Java中多线程向mysql插入同一条数据冲突问题
查看>>
Idea Maven项目使用jar包,添加到本地库使用
查看>>
FastDFS集群架构配置搭建(转载)
查看>>