Chinaunix首页 | 论坛 | 博客
  • 博客访问: 87363
  • 博文数量: 60
  • 博客积分: 4002
  • 博客等级: 中校
  • 技术积分: 645
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 18:11
文章分类

全部博文(60)

文章存档

2011年(60)

我的朋友

分类: C/C++

2011-01-02 11:20:05

    strspn 库函数用于统计字符串开头的子字符串在指定字符串中的字符的个数。

  1. #include <stdio.h>

  2. int strspn_test(const char *s, const char *accept);

  3. int
  4. main(int argc, char **argv)
  5. {
  6.     char *s = "hello andy";
  7.     char *a = "where";

  8.     printf("Result: %d\n", strspn_test(s,a));
  9.     
  10.     return 0;
  11. }

  12. int
  13. strspn_test(const char *s, const char *accept)
  14. {
  15.     const char *p;
  16.     const char *a;
  17.     int count = 0;

  18.     for (p = s; *p != '\0'; ++p) {
  19.         for (a = accept; *a != '\0'; ++a) {
  20.             if (*p == *a) {
  21.                 break;
  22.             }
  23.         }
  24.         if (*a == '\0') {
  25.             return count;
  26.         }
  27.         ++count;
  28.     }

  29.     return count;
  30. }

阅读(279) | 评论(0) | 转发(0) |
0

上一篇:strchr

下一篇:strpbrk

给主人留下些什么吧!~~