1. 程式人生 > >C語言:判斷字串是否包含

C語言:判斷字串是否包含

#include <stdio.h>

_Bool isCoincide(char *a, char *p)
{
	char *ptemp = p;
	while (*a != '\0')
	{
		if (*a == *p)
		{
			a++;
			p++;
		}
		else
		{
			a++;
			p = ptemp;
		}
		if (*p == '\0')
		{
			return 1;
		}
	}
	return 0;
}

int main()
{
	_Bool i;
	char *a = "afhajkfngj";
	char *b = "fng";

	i = isCoincide(a, b);

	printf("%d\n", i);

	getchar();

	return 0;
}