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

 

词条 strpbrk
释义

用法:#include <string.h>

功能:依次检验字符串s1中的字符,当被检验字符在字符串s2中也包含时,则停止检验,并返回该字符位置,空字符NULL不包括在内。

说明:返回s1中第一个满足条件的字符的指针,如果没有匹配字符则返回空指针NULL。

原型:extern char *strpbrk(char *s1, char *s2);

char * strpbrk(const char * cs,const char * ct)

{

const char *sc1,*sc2;

for( sc1 = cs; *sc1 != '\\0'; ++sc1) {

for( sc2 = ct; *sc2 != '\\0'; ++sc2) {

if (*sc1 == *sc2)

return (char *) sc1;

}

}

return NULL;

}

举例:

// strpbrk.c

#include <stdio.h>

#include<stdlib.h>

#include <string.h>

main()

{

char *s1="Welcome To Beijing";

char *s2="BIT";

char *p;

system("cls");

p=strpbrk(s1,s2);

if(p)

printf("%s\",p);

else

printf("Not Found!\");

p=strpbrk(s1, "Da");

if(p)

printf("%s",p);

else

printf("Not Found!");

getchar();

return 0;

}

随便看

 

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

 

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