home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / STRCREPL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  1.3 KB  |  48 lines

  1. /*
  2.  * strcrepl.c
  3.  * contains: strcreplace()
  4.  *
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include "gfuncts.h"
  9.  
  10. /*
  11.  *  char *
  12.  * strcreplace(destination,source,pos,count,n)
  13.  *
  14.  * ARGUMENT
  15.  *  (char *)    destination    -    destination string
  16.  *  (char *)    source        -    source string
  17.  *  (int)    pos        -    position to start replacement
  18.  *  (int)    count        -    Number of replacements
  19.  *  (int)    n        -    max length of destination
  20.  *
  21.  * DESCRIPTION
  22.  *  Starting at pos characters are copied from source to destination
  23.  *  until count characters have been copied or the terminating null is
  24.  *  detected in the source string or the max length of the destination
  25.  *  has been reached.
  26.  *  
  27.  * RETURNS
  28.  *  Pointer to the destination string or NULL if any of the pointer
  29.  *  arguments are NULL.  Returns NULL if n <=0 or count <=0.
  30.  *
  31.  * AUTHOR
  32.  *  ""   15-APR-1987  14:15:56.43
  33.  *   Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  34.  */
  35. char* GF_CONV strcreplace(destination,source,pos,count,n)
  36. char *destination,*source;
  37. int pos,count,n;
  38. {
  39.     char *orgdest;
  40.  
  41.     if(!destination||!source||n<=0||count<=0)
  42.         return((char *)0);
  43.     for(orgdest=destination,destination+=pos,n-=pos;*source&&count&&n;
  44.         --count,++source,++destination,--n)
  45.         *destination=*source;
  46.     return(orgdest);
  47. }
  48.