strsep函数用法
#include
c
strsep(),作为strtok的升级版,是一个很有用的字符串处理函数, 但是也有很多不方便的地方,使用时需特别小心Mssq字符串函数, 好在注意的事项都在 man strsep 里面有。如下: #include 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 #include 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); } free(string); return 0; } 运行结果: /home/yinlijun/project /home/yinlijun /home/someone -----------------------------------------------OVER------------------------------------------ (编辑:晋中站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |