strcspn()函数使用方法

strcspn
 
  原型:extern int strcspn(char *s1,char *s2);
 
  用法:#include <string.h>
 
  功能:在字符串s1中搜寻s2中所出现的字符的位置。
 
  说明:返回s2所含的字符在s1中第一次出现的位置,亦即第一个在s1中出现而s2中没有出现的字符组成的子串的长度。
 
  举例:
 
  // strcspn.c
 
  #include <syslib.h>
 
  #include <string.h>
 
  main()
 
  {
 
  char *s="Golden Global View";
 
  char *r="new";
 
  int n;
 
  clrscr();
 
  n=strcspn(s,r);
 
  printf("The first char both in s1 and s2 is: %c",s[n]);
 
  getchar();
 
  return 0;
 

  }

 

n值为4,注意,是从0 开始的。

输出为 The first char both in s1 and s2 is: e

posted @ 2012-06-09 19:39  Jawn  阅读(854)  评论(0编辑  收藏  举报