码迷,mamicode.com
首页 > 其他好文 > 详细

strspn实现方式之一

时间:2015-04-19 14:46:39      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

strspn

int ho_strspn(const char *s1, const char *s2) {
    int n = 0;
    const char *s; 
    for (; *s1; s1++, n++) {
        for (s = s2; *s && (*s1 != *s); s++) {
        }   
        if (*s == ‘\0‘)
            return n;
    }   

    return n;
}

strspn 的作用是返回s1中 第一个不在s2出现的字符的下标。

strspn 常见用法。

1.跳过空白字符

 char *p = " \t\r\nhello";

 printf("%s\n", p + ho_strspn(p, " \t\r\n"));


strspn实现方式之一

标签:

原文地址:http://my.oschina.net/guonaihong/blog/403519

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!