Linux中 strsep 函数 详解

来源:互联网 发布:阿里云cdn流量包怎么用 编辑:程序博客网 时间:2024/06/05 15:01
现出原型: 
char *strsep(char **stringp, const char *delim) 
参数1:指向字符串的指针的指针, 
参数2:指向字符的指针 
功能:以参数2所指的字符作为分界符,将参数1的值所指的字符串分割开,返回值为被参数2分开的左边的那个字符串,同时会导致参数1的值(指向位置)发生改变,即,参数1的值会指向分隔符号右边的字符串的起始位置(这一点会比较有用,比如:“1999-12-14”,可以用这个方法很容易的被提取出各个项)! 
以下是一个例子,看看运行结果你就很明白了! 
#include <string.h> 
#include <stdlib.h> 
int main() 

char ptr[]={ "abcdefghijklmnopqrstuvwxyz "}; 
char *p,*str= "m "; 
p=ptr; 
printf( "%s\n ",strsep(&p,str)); 
printf( "%s\n ",p); 
str= "s "; 
printf( "%s\n ",strsep(&p,str)); 
printf( "%s\n ",p); 

//*****结果**************结果**************结果*************************** 
[root@shwhg test]# gcc test131.c 
[root@shwhg test]# ./a.out 
abcdefghijkl 
nopqrstuvwxyz 
nopqr 
tuvwxyz 
//*************************************************************************** 
0 0