home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume28 / cproto / part02 / strstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-15  |  547 b   |  28 lines

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