home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / turbo_c / strstr.arc / STRSTR.C < prev    next >
Text File  |  1987-06-07  |  1KB  |  37 lines

  1. char *strstr (keystr, targetstr)
  2. char *keystr, *targetstr;
  3.  
  4. /*
  5.   Features of Operation:
  6.  
  7.   -  If keystr or targetstr is NULL, a NULL pointer (failure) is returned
  8.      (i.e., NULL pointer input is handled gracefully).
  9.  
  10.   -  If keystr or targetstr contains only a NULL character, a NULL pointer
  11.      (failure) is returned (i.e., NULL's are not considered characters for
  12.      the purpose of this function -- they are considered string terminators).
  13.  
  14.   -  The search terminates successfully when '\0' of keystr is encountered
  15.      before (or at the same time) as '\0' of targetstr.  The search terminates
  16.      unsuccessfully when '\0' of targetstr is reached before '\0' of keystr.
  17. */
  18.  
  19. {
  20.   register unsigned short i;
  21.  
  22.   if (keystr == (char *) 0 || targetstr == (char *) 0)
  23.     return ((char *) 0);
  24.  
  25.   if (*keystr == '\0' || *targetstr == '\0')
  26.     return ((char *) 0);
  27.  
  28.   do {
  29.     for (i = 0; *(keystr+i) && (*(keystr+i) == *(targetstr+i)); i++);
  30.     if ( !(*(keystr+i)) )
  31.       return (targetstr);
  32.   } while (*(targetstr++));
  33.  
  34.   return ((char *) 0);
  35.  
  36. }
  37.