Linux中 strsep 函数 详解

现出原型: char *strsep(char **stringp, const char *delim) 参数1:指向字符串的指针的指针, 参数2:指向字符的指针 功能:以参数2所指的字符作为分界符,将参数1的值所指的字符串分割开,返回值为被参数2分开的左边的那个字符串,同时会导致参数1的值(指向位置)发生改变,即,参数1的值会指向分隔符号右边的字符串的起始位置(这一点会比较有用,比如:“1999-12-14”,可以用这个方法很容易的被提取出各个项)! 以下是一个例子,看看运行结果你就很明白了! #include #include 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 //***************************************************************************

 

 

你可能感兴趣的:(Linux)