请输入您要查询的百科知识:

 

词条 strspn
释义

strspn(返回字符串中第一个不在指定字符串中出现的字符下标)

表头文件 #include<string.h>

定义函数 size_t strspn (const char *s,const char * accept);

函数说明 strspn()从参数s 字符串的开头计算连续的字符,而这些字符都完全是accept 所指字符串中的字符。简单的说,若strspn()返回的数值为n,则代表字符串s 开头连续有n 个字符都是属于字符串accept内的字符。

返回值 返回字符串s开头连续包含字符串accept内的字符数目。

范例

1 #include <string.h>

2 #include <stdio.h>

3 main()

4 {

5 char *str="Linux was first developed for 386/486-based pcs.";

6 printf("%d\",strspn(str,"Linux"));

7 printf("%d\",strspn(str,"/-"));

8 printf("%d\",strspn(str,"1234567890"));

9 }

运行结果:

5

0

0

函数原型:

int strspn(const char *s, const char *accept)

{

const char *p;

const char *a;

size_t count = 0;

for (p = s; *p != '\\0'; ++p) {

for (a = accept; *a != '\\0'; ++a) {

if (*p == *a)

break;

}

if (*a == '\\0')

return count;

++count;

}

return count;

}

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/2/25 5:17:19