strpbrk

头文件:#include <include.h>

strpbrk()函数检索两个字符串中首个相同字符的位置,其原型为:
char *strpbrk( char *s1, char *s2);

【参数说明】s1、s2要检索的两个字符串。

strpbrk()从s1的第一个字符向后检索,直到'\0',如果当前字符存在于s2中,那么返回当前字符的地址,并停止检索。

【返回值】如果s1、s2含有相同的字符,那么返回指向s1中第一个相同字符的指针,否则返回NULL。

注意:strpbrk()不会对结束符'\0'进行检索。

【函数示例】输出第一个相同字符之后的内容。
   
   
  1. #include<stdio.h>
  2. #include<string.h>
  3. int main(void){
  4. char* s1 = "http://see.xidian.edu.cn/cpp/u/xitong/";
  5. char* s2 = "see";
  6. char* p = strpbrk(s1,s2);
  7. if(p){
  8. printf("The result is: %s\n",p);
  9. }else{
  10. printf("Sorry!\n");
  11. }
  12. return 0;
  13. }
#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/
  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值