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

 

词条 strcspn
释义

原型:size_t strcspn(const char *s1,const char *s2);

相关头文件:#include <string.h>

功能:顺序在字符串s1中搜寻与s2中字符的第一个相同字符,返回这个字符在S1中第一次出现的位置。

说明:(返回第一个出现的字符在s1中的下标值,亦即在s1中出现而s2中没有出现的子串的长度。)

简单地说,若strcspn()返回的数值为n,则代表字符串s1开头连续有n个字符都不含字符串s2内的字符。

举例:

// strcspn.c

#include <stdio.h >

#include <syslib.h>

#include <string.h>

int main(void)

{

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;

}

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

随便看

 

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

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/3/1 20:42:20