天天看点

strchr函数的简单实现

#include <stdio.h>
#include <string.h>

char *my_strchr(char *s,char c)
{
	char *p = s;
	while(*p && *p != c)
		p++;
	if(*p == c)
		return p;
	return NULL;
}

int main(void)
{
	char buf[20] = "Hello World";
	char c = 'l';
	char *p = my_strchr(buf,c);
	if(p != NULL)
		printf("%s\n",p);
	else
		printf("No this character in the string!\n");

	return 0;
}
           

继续阅读