字符数组

C语言中的标准函数库中的strchr()函数可以实现查找字符串中的某个字符。

头文件: #include <string.h>

函数原型:char *strchr(const char *s, int c);

函数说明:从左向右,在字符串s中查找字符c首次出现的位置,如果找到返回c在s中的位置(指针),否则返回NULL

#include <stdio.h>
#include <string.h>
void main()
{
    char str[]="hello world";
    char *p=strchr(str, 'w');
    if ( p )
        printf("find 'w'!);
    else
        printf("not found!");
}
相关函数:

char *strrchr(const char *s, int c); 从右向左,查找s中最右边的匹配字符位置

char *strstr(const char *s, const char *sub); //在s中查找sub子串出现的位置
posted @ 2017-12-24 18:00  A-Little-Nut  阅读(205)  评论(0编辑  收藏  举报