博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
strpbrk函数
阅读量:4586 次
发布时间:2019-06-09

本文共 888 字,大约阅读时间需要 2 分钟。

函数原型:extern char *strpbrk(char *str1, char *str2)

参数说明:str1待比较的字符串,str2为指定被搜索的字符串。

        
所在库名:#include <string.h>
  
函数功能:比较字符串str1和str2中是否有相同的字符,如果有,则返回该字符在str1中的位置的指针。
  
返回说明:返回指针,搜索到的字符在str1中的索引位置的指针。

其它说明:暂时无。

实例:

#include
<
string
.h
>
#include
<
stdio.h
>
int
 main()
{
    
char *str1="please try again,sky2098!";
    
char *str2="Hello,I am sky2098,I like writing!";
    
char *strtemp;
    strtemp
=strpbrk(str1,str2);  //搜索进行匹配
    printf("Result is:  %s ",strtemp);
    
return 0;
}

在VC++ 6.0  编译运行:

返回了str2中字符“l”在str1中位置的指针,打印出字符串“lease try again,sky2098!”。

如果str2中所有字符都没有在str1中出现过,则返回null:

#include
<
string
.h
>
#include
<
stdio.h
>
int
 main()
{
    
char *str1="aaaaaaabbbbbbbcccccccc";  //str1中的任何一个字符在str2中都找不到
    char *str2="ppppkkkkmmmer";
    
char *strtemp;
    strtemp
=strpbrk(str1,str2);
    printf(
"Result is:  %s ",strtemp);
    
return 0;
}

在VC++ 6.0  编译运行:

返回了空值。

转载于:https://www.cnblogs.com/lgh1992314/archive/2012/11/02/5835364.html

你可能感兴趣的文章
python pip源配置,pip配置文件存放位置
查看>>
[数据库]关于MAX()函数的一个坑
查看>>
实现前后滚动效果-axure设计实例
查看>>
windows下mysql忘记root密码--吐血测试,都是泪
查看>>
lnmp集成开发环境安装pdo_dblib扩展
查看>>
linux web.py spawn-fcgi web.py 配置
查看>>
lintcode : 空格替换
查看>>
lintcode 中等题:subsets II 带重复元素的子集
查看>>
【原创】Linux基础之测试域名IP端口连通性
查看>>
webstorm快捷键大全
查看>>
SQL Server 语法大全
查看>>
MySQL存储过程
查看>>
HttpContext是干什么的
查看>>
线程安全
查看>>
原形模式
查看>>
iOS开发笔记5:多线程之NSThread、NSOperation及GCD
查看>>
php中curl的详细解说【转】
查看>>
Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分
查看>>
hdu 6069 Counting Divisors 筛法
查看>>
codeforces gym 100971 K Palindromization 思路
查看>>