home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / actlib12.zip / STRINGS.ZIP / MID.C < prev    next >
Text File  |  1993-01-14  |  1KB  |  39 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "strings.h"
  4.  
  5. /***
  6.  *  Function    :  strmid
  7.  *
  8.  *  Description :  Copy n characters of a string, begining at a given position
  9.  *           ( form 1 to ... )
  10.  *
  11.  *  Decisions   :  Stops at the end of input string if given length
  12.  *           is too big or length = 0.
  13.  *           If given length or position < 0 returns an empty string.
  14.  *
  15.  *  Parameters  :  out  char  *out_str     result
  16.  *                 in   char  *in_str      in string
  17.  *                 in   int   pos          position where begin to copy
  18.  *                 in   int   length       length to be copied
  19.  *
  20.  *  Return code :   pointer to result.
  21.  *
  22.  *  OS/Compiler :   All
  23.  */
  24.  
  25. char *strmid( char *out_str, const char    *in_str, int pos, int length )
  26. {
  27.  
  28. if ( (length < 0) || (pos <= 0)  ) { *out_str = '\0';
  29.                       return(out_str);
  30.                     }
  31.  
  32. for (; pos; pos -- ) if ( ! *in_str++ ) { *out_str = '\0';
  33.                         return(out_str);
  34.                       }
  35. in_str --;
  36.  
  37. return( strleft(out_str,in_str,length) );
  38. }
  39.