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

  1.  
  2. /*
  3.  * Copyright (C) 1990 by Jay Konigsberg. mail: jak@sactoh0
  4.  *
  5.  * Permission to use, copy, modify, and distribute this  software  and  its
  6.  * documentation is hereby  granted,  provided  that  the  above  copyright
  7.  * notice appear in all copies  and that  both  the  copyright  notice  and
  8.  * this permission notice appear in supporting documentation. This software
  9.  * is provided "as is" without express or implied  warranty.  However,  the
  10.  * author retains all Copyright priviliges and rights  to  renumeration  if
  11.  * this software is sold.
  12.  */
  13.  
  14. /*
  15.  * position - locate the first occurence of substr in string and
  16.  * return the subscript
  17.  */
  18.  
  19. #include "simped.h"
  20.  
  21. int position(substr, string)
  22. char substr[];
  23. char string[];
  24. {
  25. int    strinx,        /* index for string */
  26.     subinx,        /* index for substr */
  27.     sublen,        /* length of substr */
  28.     found=FALSE;    /* boolean - is a match found? */
  29.  
  30. sublen=strlen(substr);
  31. for(strinx=0; strinx < strlen(string); ++strinx)
  32.     {
  33.     for (subinx=0; subinx < sublen; ++subinx)
  34.     {
  35.     if (substr[subinx] == string[strinx+subinx])
  36.         {
  37.         found=TRUE;
  38.         }
  39.     else
  40.         {
  41.         found=FALSE;
  42.         break;
  43.         }
  44.     }
  45.     if (subinx == sublen && found)
  46.     break;
  47.     }
  48. if (! found)
  49.     strinx = -1;
  50. return(strinx);
  51. }
  52.