strchr函数
字符查找函数
头文件:#include <string.h>
函数定义:char* strchr(const char* s, int c);
函数说明:
在字符指针s指向的字符串,找ASCII码为c的字符
注意:是首次匹配,如果说s指向的字符串中有多个ASCII为c的字符,则找的是第一个字符的返回值;
找到了返回找到的字符的地址,找不到返回NULL
*/
#include <stdio.h>
#include <string.h>
#pragma warning(disable:4996)
int main()
{
char* str = "helloworldhelloworldhelloworld";
char* p;
p = strchr(str, 'w');
if (p == NULL)
{
printf("没有您要找的字符\n");
return 0;
}
printf("p-str=%d\n", p - str);
return 0;
}//p-str=5