C 库函数

定义

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

参数

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

说明

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

例子

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

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

   ret = strchr(str, ch);

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

输出

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

参考:

https://www.runoob.com/cprogramming/c-function-strchr.html

原文地址:https://www.cnblogs.com/sea-stream/p/11219582.html