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

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "strings.h"
  4.  
  5. /***
  6.  *  Function    :  strinsert
  7.  *
  8.  *  Description :  Insert a string in another.
  9.  *
  10.  *  Parameters  :  in   char   *out_str    out string
  11.  *                 in   char   *in_str     in string 
  12.  *                 in   char   *to_insert  in string to insert into the other
  13.  *                 in   int    place       place to insert string
  14.  *                                        
  15.  *  Decisions   :  Does nothing if place specified out of range.
  16.  *
  17.  *  Return      :  pointer to result
  18.  *
  19.  *  OS/Compiler :  All
  20.  ***/
  21.  
  22. char *strinsert( char *out_str, const char *in_str, const char *to_insert, int place )
  23.  
  24. { char *out_ptr = out_str, buffer[255], *ptr = buffer;
  25.  
  26.   if ( place <= 0 ) return ptr;
  27.                            
  28.   if ( in_str == out_str ) { while( -- place ) if ( ! *out_str++ ) return(out_ptr);
  29.                    while ( *ptr++ = *in_str++ ); /* strcpy : used if in_str = out_str */
  30.                  ptr = buffer;
  31.                }
  32.               else { while( -- place ) if ( ! (*out_str++ = *in_str++) ) return(out_ptr);
  33.                        ptr = in_str;
  34.                }
  35.  
  36.   while( *out_str++ = *to_insert++ );
  37.   out_str --;
  38.  
  39.   while ( *out_str++ = *ptr++ );
  40.  
  41.   return out_ptr;
  42. }
  43.