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

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;

}

你可能感兴趣的:(null)