home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 337_01 / l_copy.c < prev    next >
C/C++ Source or Header  |  1991-01-14  |  1KB  |  38 lines

  1. /* Copyright (c) James L. Pinson 1990,1991  */
  2.  
  3. /**********************   L_COPY.C   ***************************/
  4.  
  5. #include "mydef.h"
  6.  
  7.  
  8. /*****************************************************************
  9.  
  10.  Usage: void copy (char *from,char *to,int first,int length);
  11.  
  12.   char *from  = string to copy from.
  13.   char *to    = string to copy to.
  14.   int first   = position within string to start copying.
  15.   int length  = number of character to copy.
  16.  
  17.   Copies a section of text, beginning at position "first" in
  18.   string "from" and copies "length" number to string "to".
  19.   (zero based counting, begins at zero not one)
  20.  
  21.   Example: copy (&to "test",1,2);
  22.            results: to = "es"
  23.  
  24. *****************************************************************/
  25.  
  26. void copy (char *from,char *to,int first,int length)
  27. {
  28. int i;
  29.  if ( (first <0) ) return;  /*  invalid number */
  30.  
  31.  /* if attempt made to copy beyond end of string then adjust*/
  32.  if((first+length+1 ) > strlen(from))length=strlen(from)-first ;
  33.  
  34.   for(i=0;i<length;i++)
  35.    to[i]= from[(first)+i];
  36.   to[i]='\0';
  37. }
  38.