[Coco] "C string searching question

Gene Heskett gheskett at wdtv.com
Tue Oct 2 12:34:38 EDT 2012


On Tuesday 02 October 2012 12:32:59 Retro Canada did opine:

> Then strstr is what you need. If you don't have it you MAKE it :)
> 
> 
> const char * strstr (
> 	const char * str1,
> 	const char * str2
> 	)
> {
> 	const char * cp = str1;
> 	const char * s1;
> 	const char * s2;
> 
> 	if ( !*str2 )
> 	    return str1;
> 
> 	while (*cp)
> 	{
> 		s1 = cp;
> 		s2 = str2;
> 
> 		while ( *s1 && *s2 && !(*s1-*s2) )
> 			s1++, s2++;
> 
> 		if (!*s2)
> 			return( (char*)cp );
> 
> 		cp++;
> 	}
> 
> 	return 0 ;
> }

Thank you.  The next time I do some C work on my coco, I'll add this to 
c.lib.

Cheers, Gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
My web page: <http://coyoteden.dyndns-free.com:85/gene> is up!
The difference between legal separation and divorce is that legal
separation gives the man time to hide his money.



More information about the Coco mailing list