home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cproto.zip / cproto46 / strstr.c < prev    next >
C/C++ Source or Header  |  1994-10-12  |  601b  |  33 lines

  1. /* $Id: strstr.c,v 4.1 1994/10/12 14:12:48 cthuang Exp $
  2.  *
  3.  * Simple implementation of the ANSI strstr() function
  4.  */
  5. #include <stdio.h>
  6.  
  7. #include "cproto.h"
  8.  
  9. /* Search for a substring within the given string.
  10.  * Return a pointer to the first occurence within the string,
  11.  * or NULL if not found.
  12.  */
  13. #if !HAVE_STRSTR
  14. char *
  15. strstr (src, key)
  16. char *src, *key;
  17. {
  18.     char *s;
  19.     int keylen;
  20.  
  21.     if ((keylen = strlen(key)) == 0)
  22.     return src;
  23.  
  24.     s = strchr(src, *key);
  25.     while (s != NULL) {
  26.     if (strncmp(s, key, keylen) == 0)
  27.         return s;
  28.     s = strchr(s+1, *key);
  29.     }
  30.     return NULL;
  31. }
  32. #endif
  33.