TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Frank Adam
from: Paul Edwards
date: 1996-06-13 19:05:02
subject: Find a word

PE> /* strstr by Frank Adam */

FA> char *strstr(const char *s1, const char *s2)
FA> {
FA>  const char *p = s1, *p1 = s2, *p2;

FA>   while (*p)   /* this ++ is suspicous. No, it's not, just wrong:) */
FA>   {
FA>    if (*p == *p1)
FA>    {
FA>     p2 = p;       
FA>     while (*p++ == *p1 && *p1++) /* ";" whoops! */

I think you want a ";" here.  ";" is equivalent to
"{}".  You
want a do-nothing loop, no?  BFN.  Paul.


FA>     if (!*p1) 
FA>     {
FA>      return (char *)p2;
FA>      }
FA>     p = p2;  /* p = ++p2; ah-oh, another bug morteined. */
FA>     p1 = s2;   
FA>       }
FA>    p++;   
FA>    }    
FA>    return NULL;
FA>  }

BFN.  Paul.
@EOT:

---
* Origin: X (3:711/934.9)

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.