I.函数strchr()
函数头文件:include <string.h>
函数原型:char *strchr(const char *s, int c);
功能:在字符串s中查找字母c出现的位置
参数:
s:字符串首地址
c:匹配字母(字符)
返回值:
成功:返回第一次出现的c地址
失败:NULL
#include <stdio.h>
#include<string.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
char *src = "hello world and welcome to you.";
char *mPtr = NULL;
mPtr = strchr(src,'t');
if (mPtr != NULL)
{
printf("%s\n",mPtr);
}
system("pause");
return 0;
}
打印结果:
to you.
现在把mPtr = strchr(src,'t');换成mPtr = strchr(src,'x');如下:
#include <stdio.h>
#include<string.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
char *src = "hello world and welcome to you.";
char *mPtr = NULL;
mPtr = strchr(src,'x');
if (mPtr != NULL)
{
printf("%s\n",mPtr);
}
else
{
puts(&#
c语言函数strchr(),strstr(),strtok()
最新推荐文章于 2023-03-28 09:32:06 发布