home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d536 / increv.lha / IncRev / src.lzh / strpos.c < prev   
C/C++ Source or Header  |  1991-08-23  |  1KB  |  43 lines

  1. /***************************************************************************
  2. * strpos.c: returns index of string2 in string1 or -1 if not found       *
  3. *                                       *
  4. * initially created somewhen in 1990                       *
  5. ***************************************************************************/
  6.  
  7. /* --------------------- source code revisions, tracked by RCS ---------- */
  8.  
  9. /* $Header: Hard0:C-Compiler/src/increv/rcs/strpos.c,v 1.0.1.2 91/08/12 15:04:19 Mtwx Exp Locker: Mtwx $ */
  10. /* $Log:    strpos.c,v $
  11.  * Revision 1.0.1.2  91/08/12  15:04:19  Mtwx
  12.  * - RCS test, no real change!
  13.  * 
  14.  * Revision 1.0.1.1  91/08/12  15:02:56  Mtwx
  15.  * - added (Metalworx-) comments and styles
  16.  *
  17.  * Revision 1.0  91/08/12  14:59:03  Mtwx
  18.  * Initial revision
  19.  *  */
  20.  
  21. /* ------------------------------- routines ----------------------------- */
  22.  
  23. int strpos(s1,s2)
  24. char *s1,*s2;
  25. {
  26.   register int i;
  27.   int n,pos=0,flag=0;
  28.  
  29.   if(strlen(s2) > strlen(s1)) return -1;
  30.   for(i=0;i<strlen(s1)-strlen(s2)+1;i++)
  31.   {
  32.     n=strncmp(&s1[i],s2,strlen(s2));
  33.     if(n==0)
  34.     {
  35.       pos=i;
  36.       flag=1;
  37.       break;
  38.     }
  39.   }
  40.   if(!flag) pos=-1;
  41.   return pos;
  42. }
  43.