strsep函数用法
来源:互联网 发布:免费拆单软件 编辑:程序博客网 时间:2024/06/06 02:18
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------------------------------------------
- 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 函数说明
- uva 10142
- css 百分比 定义高度 小结
- 要质问,请你先了解下事件的真像
- 播放动画文件
- 项目部署
- strsep函数用法
- VC++实现输入字符动态更新列表查询
- Visual SourceSafe 入门教学
- VS2008查看WinForm界面遇到的问题
- 位图索引
- 视频播放魔法师与兔子时,出现死机
- 初识vb利用ADO访问数据库
- zlib压缩库备忘
- /proc/meminfo and procrank (procrank | busybox grep launcher)