
C语言的strchr()函数用于在给定的字符串中查找特定字符.
头文件: string.h

语法/原型:
char * strchr(const char * strc strchr函数,int c);

参数说明:
strchr()函数按顺序搜索字符串str中的每个字符,直到遇到字符c或到达字符串结尾(满足\ 0)为止.

返回值: 第一次返回字符c在字符串str中的位置c strchr函数,如果找不到字符c,则返回NULL.
【示例】使用C语言strchr()函数在C语言中文网站中找到g字符.

#include <stdio.h>
#include <string.h>
int main(){
const char *str = "http://c.biancheng.net/";
int c = 'g';
char *p = strchr(str, c);
if (p) {
puts("Found");
} else {
puts("Not found");
}
return 0;
}运行结果:
找到
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-164014-1.html
手好看