home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 554b.lha / WFile_v1.10 / source / strpos.c < prev    next >
Encoding:
Text File  |  1991-09-10  |  916 b   |  36 lines

  1. /***************************************************************************
  2. * strpos.c: returns index of string2 in string1 or -1 if not found       *
  3. *                                       *
  4. * created: Oct-90 Mtwx                               *
  5. ***************************************************************************/
  6.  
  7. /* --------------------- source code revisions, tracked by RCS ---------- */
  8.  
  9. /* $Header: Hard0:C-Compiler/src/wfile/rcs/strpos.c,v 1.0 91/08/12 20:27:15 Mtwx Exp $ */
  10. /* $Log:    strpos.c,v $
  11.  * Revision 1.0  91/08/12  20:27:15  Mtwx
  12.  * Initial revision
  13.  *  */
  14.  
  15. /* ------------------------------- routines ----------------------------- */
  16.  
  17. int strpos(char *s1, char *s2)
  18. {
  19.   register int i;
  20.   int n,pos=0,flag=0;
  21.  
  22.   if(strlen(s2) > strlen(s1)) return -1;
  23.   for(i=0;i<strlen(s1)-strlen(s2)+1;i++)
  24.   {
  25.     n=strncmp(&s1[i],s2,strlen(s2));
  26.     if(n==0)
  27.     {
  28.       pos=i;
  29.       flag=1;
  30.       break;
  31.     }
  32.   }
  33.   if(!flag) pos=-1;
  34.   return pos;
  35. }
  36.