strsep函数用法
来源:互联网 发布:mac照片下一张 编辑:程序博客网 时间:2024/06/06 02:09
strsep(),作为strtok的升级版,是一个很有用的字符串处理函数, 但是也有很多不方便的地方, 使用时需特别小心, 好在注意的事项都在 man strsep 里面有。如下:
#include <string.h>
char *strsep(char **stringp, const char *delim);
Be cautious when using this function. If you do use it, note that:
* This function modifies its first argument.
* This function cannot be used on constant strings.
* The identity of the delimiting character is lost.
实例:
#include <string>
#include <stdio.h>
int main(int arg, const char *argv[])
{
char* string = strdup( "/home/yinlijun/project:/home/yinlijun:/home/someone"); /*字符串不能为常量,所以strdup*/
char* p;
while((p = strsep(&string, ":")) != NULL) /*第一个参数设为二级指针, 字符串中所有的第二个参数(子串)最后会被替代成‘/0’*/
{
printf("%s/n", p);
}
return 0;
}
运行结果:
/home/yinlijun/project
/home/yinlijun
/home/someone
-----------------------------------------------OVER------------------------------------------
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yinlijun2004/archive/2010/07/16/5740068.aspx
- strsep函数用法
- strsep函数用法
- strsep 函数
- strsep 函数
- strsep函数
- strsep() 函数
- strsep的用法
- Linux strsep() 用法
- 字符串分割函数strsep
- 字符串分割 strsep 函数
- Linux中 strsep 函数 详解
- strsep 函数 c 语言 实现
- strtok和strsep函数详解
- strtok和strsep函数详解
- strtok 与 strsep 函数说明
- strtok和strsep函数详解
- strtok和strsep函数详解
- strtok 与 strsep 函数说明
- Oracle笔记 一、oracle的安装、sqlplus的使用
- 硬盘空间管理原理(转)
- Unix/Linux历史和大事记(转)
- linux-gcc 编译时头文件和库文件搜索路径(+可执行文件、包)
- 由一幅漫画想到的
- strsep函数用法
- SQL Server 2005解决死锁
- 谁是搜索引擎的挑战者
- 欧盟 物联网战略研究路线图 翻译稿 初稿 0
- java 工厂模式详解
- Win7安装和配置webNetwork
- 八款开源ANDROID游戏引擎
- 设置QT/linux -arm下的桌面及窗口 按键的背景 图片
- linux判断文件是否存在