C语言 strchr

C语言 strchr

#include <string.h>
char *strchr(const char *s, int c);

功能:在字符串s中查找字母c出现的位置
参数:

  • s:字符串首地址
  • c:匹配字母(字符)

返回值:

  • 成功:返回第一次出现的c地址
  • 失败:NULL

案例

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

int main(void)
{
    char ch[] = "hello world";
    char c = 'w';
    // 查找字符串
    char* p = strchr(ch, c);
    printf("%s\n", p);

    return 0;
}
strchr 使用案例

 

posted @ 2020-02-28 19:00  kevin.Xiang  阅读(550)  评论(0编辑  收藏  举报