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

查看所有标签

Programming Python

Programming Python

Mark Lutz / O'Reilly Media / 2006-8-30 / USD 59.99

Already the industry standard for Python users, "Programming Python" from O'Reilly just got even better. This third edition has been updated to reflect current best practices and the abundance of chan......一起来看看 《Programming Python》 这本书的介绍吧!

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

在线压缩/解压 JS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具