home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1456 / position.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  828 b   |  44 lines

  1.  
  2. /*
  3.  * Copyright (C) 1990 Jay Konigsberg - see Makefile for details
  4.  * This is Free Software, distrubited under the GNU Software Aggrement.
  5.  */
  6.  
  7. /*
  8.  * position - locate the first occurence of substr in string and
  9.  * return the subscript
  10.  */
  11. #include "simped.h"
  12.  
  13. int position(substr, string)
  14. char substr[];
  15. char string[];
  16. {
  17. int    strinx,        /* index for string */
  18.     subinx,        /* index for substr */
  19.     sublen,        /* length of substr */
  20.     found=FALSE;    /* boolean - is a match found? */
  21.  
  22. sublen=strlen(substr);
  23. for(strinx=0; strinx < strlen(string); ++strinx)
  24.     {
  25.     for (subinx=0; subinx < sublen; ++subinx)
  26.     {
  27.     if (substr[subinx] == string[strinx+subinx])
  28.         {
  29.         found=TRUE;
  30.         }
  31.     else
  32.         {
  33.         found=FALSE;
  34.         break;
  35.         }
  36.     }
  37.     if (subinx == sublen && found)
  38.     break;
  39.     }
  40. if (! found)
  41.     strinx = -1;
  42. return(strinx);
  43. }
  44.