TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Paul Edwards
from: Frank Adam
date: 1996-01-01 01:32:08
subject: Find a word

G'Day Paul,
 
-=> Quoting Paul Edwards to Frank Adam <=-

 PE> P.S. I used it, but it didn't work properly.  Wanna modify this
 PE> (formatted) version so that it works?

 PE> /* strstr by Frank Adam */

char *strstr(const char *s1, const char *s2)
{
 const char *p = s1, *p1 = s2, *p2;
  
  while (*p)   /* this ++ is suspicous. No, it's not, just wrong:) */
  {
   if (*p == *p1)
   {
    p2 = p;       
    while (*p++ == *p1 && *p1++) /* ";" whoops! */
    if (!*p1) 
    {
     return (char *)p2;
     }
    p = p2;  /* p = ++p2; ah-oh, another bug morteined. */
    p1 = s2;   
      }
   p++;   
   }    
   return NULL;
 }

Ok, it should work now, p++ missed the first character of the string,
the semicolon should not have been there, that was a typo, also picked
up on p = ++p2  being wrong, would have missed consecutive chars.
Obviously you've tested this better than i did :) 
3 bugs in 20 lines, i sure hope it's not my average...       
Of course this makes stristr the same with tolower()s or toupper()s 
applied to *p and *p1 in the comparisons.

  L8r Frank (fadam{at}ozemail.com.au).
  
___ Blue Wave/DOS v2.21
                           

--- Maximus 3.01
* Origin: The Software Parlour (3:635/544)
SEEN-BY: 50/99 620/243 623/630 632/349 635/503 544 727 711/401 409 410 413
SEEN-BY: 711/430 808 809 932 934 712/515 713/888 714/906 800/1
@PATH: 635/544 50/99 711/808 934

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™.