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://codercto.com/courses/l/17.html

查看所有标签

Spring

Spring

Bruce Tate、Justin Gehtland / O'Reilly Media, Inc. / 2005-04-12 / USD 29.95

Since development first began on Spring in 2003, there's been a constant buzz about it in Java development publications and corporate IT departments. The reason is clear: Spring is a lightweight Java......一起来看看 《Spring》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

随机密码生成器
随机密码生成器

多种字符组合密码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换