指针_字符串搜索(find_char)

题意,在字符串A中搜索,如果在A中出现任何字符串B中的字符,则指针指向字符串A中的那个字符


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

char *find_char(char const *source,char const *chars)
{
	int len = strlen(source);
	int sublen = strlen(chars);
	int i;
	int j;
	for(i = 0;i<len;i++)
	{
		for(j = 0;j<sublen;j++)
		{
			if(*source == *chars){
				return (char*)source;}
			else
			{
				chars ++;
			}

		}
		chars -= sublen;
		source++;
	}
    return 0;
}

int main()
{
	char str[] = "lifeishard";
	char chars[] = "comeon";
	char *p;
	p = find_char(str,chars);
	printf("%s\n",p);
    return 0;
}


猜你喜欢

转载自blog.csdn.net/blackholeAC/article/details/6932917