C 库函数 - strchr()

C 语言教程 · 2019-02-24 14:27:18

描述

C 库函数 char *strchr(const char *str, int c) 在参数 str 所指向的字符串中搜索第一次出现字符 c(一个无符号字符)的位置。

声明

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

char *strchr(const char *str, int c)

参数

  • str -- 要被检索的 C 字符串。
  • c -- 在 str 中要搜索的字符。

返回值

该函数返回在字符串 str 中第一次出现字符 c 的位置,如果未找到该字符则返回 NULL。

实例

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

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

int main ()
{
   const char str[] = "http://www.codercto.com";
   const char ch = '.';
   char *ret;

   ret = strchr(str, ch);

   printf("|%c| 之后的字符串是 - |%s|\n", ch, ret);
   
   return(0);
}

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

|.| 之后的字符串是 - |.codercto.com|

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

查看所有标签

Thirty-three Miniatures

Thirty-three Miniatures

Jiří Matoušek / American Mathematical Socity / 2010-6-18 / USD 24.60

This volume contains a collection of clever mathematical applications of linear algebra, mainly in combinatorics, geometry, and algorithms. Each chapter covers a single main result with motivation and......一起来看看 《Thirty-three Miniatures》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

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

在线压缩/解压 CSS 代码

在线进制转换器
在线进制转换器

各进制数互转换器