// 模拟实现strchr函数,功能:在一个字符串中查找一个字符第一次出现的位置,如果没有出现返回NULL
#include <stdio.h>
#include <assert.h>
char const* my_strchr(char const *p,char c)
{
assert(p != NULL);
while (*p)
{
if (*p == c)
return p;
else
p++;
}
return NULL;
}
int main()
{
char *p = "zhaoyaqian";
printf("字符串是:%s\n", p);
printf("位置:%p\n", my_strchr(p, 'a'));
printf("位置:%p\n", my_strchr(p, 'c'));
return 0;
}
<img src="https://img-/20150702101456412?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3lhcWlhbjU1Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />