Linux strsep() 用法

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 <stdio.h> 
#include <string.h>
int main(void)
{   
    char s[] = "hello world!";
    char *p = s; 
    char *d = " ";  
    printf("%s\n", strsep(&p, d));    
    printf("%s\n", p);  
    return 0;
}
函數打印如下:helloworld!


發佈了18 篇原創文章 · 獲贊 12 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章