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

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "strings.h"
  4.  
  5. /***
  6.  *  Function    :  strright
  7.  *
  8.  *  Description :  Copy the last ... characters of a string.
  9.  *
  10.  *  Decisions   :  If given length > string length : normal strcpy
  11.  *           If given length <= 0 returns an empty string.
  12.  *
  13.  *  Parameters  :  out  char  *out_str     result
  14.  *                 in   char  *in_str      in string
  15.  *                 in   int   length       length to be copied
  16.  *
  17.  *  Return code :   pointer to result.
  18.  *
  19.  *  OS/Compiler :   All
  20.  */
  21.  
  22. char *strright( char *out_str, const char *in_str, int length )
  23.  
  24. { const char *ptr = in_str;
  25.  
  26.   if ( length <= 0 ) { *out_str = '\0';
  27.                return out_str;
  28.              }
  29.  
  30.   while ( *ptr++ );
  31.  
  32.   if ( ptr - length - 1 > in_str ) in_str = ptr - length - 1;
  33.  
  34.   return strcpy( out_str, in_str );
  35. }
  36.