C 库函数 - strpbrk()

C 语言教程 · 2019-02-24 16:44:27

描述

C 库函数 char *strpbrk(const char *str1, const char *str2) 检索字符串 str1 中第一个匹配字符串 str2 中字符的字符,不包含空结束字符。也就是说,依次检验字符串 str1 中的字符,当被检验字符在字符串 str2 中也包含时,则停止检验,并返回该字符位置。

声明

下面是 strpbrk() 函数的声明。

char *strpbrk(const char *str1, const char *str2)

参数

  • str1 -- 要被检索的 C 字符串。
  • str2 -- 该字符串包含了要在 str1 中进行匹配的字符列表。

返回值

该函数返回 str1 中第一个匹配字符串 str2 中字符的字符数,如果未找到字符则返回 NULL。

实例

下面的实例演示了 strpbrk() 函数的用法。

#include <stdio.h>
#include <string.h>

int main ()
{
   const char str1[] = "abcde2fghi3jk4l";
   const char str2[] = "34";
   char *ret;

   ret = strpbrk(str1, str2);
   if(ret) 
   {
      printf("第一个匹配的字符是: %c\n", *ret);
   }
   else 
   {
      printf("未找到字符");
   }
   
   return(0);
}

让我们编译并运行上面的程序,这将产生以下结果:

第一个匹配的字符是: 3

点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html

查看所有标签

Distributed Algorithms

Distributed Algorithms

Wan Fokkink / The MIT Press / 2013-12-6 / USD 40.00

This book offers students and researchers a guide to distributed algorithms that emphasizes examples and exercises rather than the intricacies of mathematical models. It avoids mathematical argumentat......一起来看看 《Distributed Algorithms》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

MD5 加密
MD5 加密

MD5 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具