C/C++ Example Procedure: strstr - Find ASCII c-string (substring) in ASCII c-string

See related: C/C++ Examples

Returns NULL (0) pointer when substring is not found in string, otherwise, returns pointer in str where substr was found.

char* strstr(char *str, char *substr)
{
	if(!*substr)
		return str;
	for(char* a, *b = substr; *str; str++)
	{
		if (*str != *b)
			continue;
		a = str;
		while (1)
		{
			if (!*b)
				return str;
			if (*a++ != *b++)
				break;
		}
		b = substr;
	}
	return 0;
}

Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site.
OK