头文件:#include <include.h>
strpbrk()函数检索两个字符串中首个相同字符的位置,其原型为:
char *strpbrk( char *s1, char *s2);
【参数说明】s1、s2要检索的两个字符串。
strpbrk()从s1的第一个字符向后检索,直到'\0',如果当前字符存在于s2中,那么返回当前字符的地址,并停止检索。
【返回值】如果s1、s2含有相同的字符,那么返回指向s1中第一个相同字符的指针,否则返回NULL。
注意:strpbrk()不会对结束符'\0'进行检索。
【函数示例】输出第一个相同字符之后的内容。
- #include<stdio.h>
- #include<string.h>
- int main(void){
- char* s1 = "http://see.xidian.edu.cn/cpp/u/xitong/";
- char* s2 = "see";
- char* p = strpbrk(s1,s2);
- if(p){
- printf("The result is: %s\n",p);
- }else{
- printf("Sorry!\n");
- }
- return 0;
- }
#include<stdio.h>
#include<string.h>
int main(void){
char* s1 = "http://see.xidian.edu.cn/cpp/u/xitong/";
char* s2 = "see";
char* p = strpbrk(s1,s2);
if(p){
printf("The result is: %s\n",p);
}else{
printf("Sorry!\n");
}
return 0;
}
输出结果:
The result is: see.xidian.edu.cn/cpp/u/xitong/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)