vfb.c中学习到的循环检测以逗号分割的字符串各个值的处理

来源:互联网 发布:java应届生简历 编辑:程序博客网 时间:2024/05/07 08:40

char * options;

//循环检测以逗号分割的options字符串各个值,如果发现disable则设置vfb_enable = 0

while ((this_opt = strsep(&options, ",")) != NULL) {

              if (!*this_opt)

                     continue;

              if (!strncmp(this_opt, "disable", 7))

                     vfb_enable = 0;

       }

//返回第一个值sbegin,并修改字符串首地址*s,指向第二个参数

char * strsep(char **s, const char *ct)

{

       char *sbegin = *s, *end;

 

       if (sbegin == NULL)

              return NULL;

 

       end = strpbrk(sbegin, ct);

       if (end)

              *end++ = '/0';

       *s = end;

 

       return sbegin;

}

 

//返回在cs中第一个和ct相等的字符位置

char * strpbrk(const char * cs,const char * ct)

{

       const char *sc1,*sc2;

 

       for( sc1 = cs; *sc1 != '/0'; ++sc1) {

              for( sc2 = ct; *sc2 != '/0'; ++sc2) {

                     if (*sc1 == *sc2)

                            return (char *) sc1;

              }

       }

       return NULL;

}
原创粉丝点击