home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 9
/
CD_ASCQ_09_1193.iso
/
maj
/
4331
/
strings.exe
/
MVSTR.C
< prev
next >
Wrap
Text File
|
1993-01-14
|
1KB
|
46 lines
/* Copyright (C) 1993 Marc Stern (internet: stern@mble.philips.be) */
#include "strings.h"
/***
* Function : strmvstr
*
* Description : Copy an input string in an output string
* with replacing all occurences of a target string.
*
* Parameters : out char *out_str result
* in char *in_str in string
* in char *target target string to replace
* in char *new_str string to put in place of target
*
* Return code : pointer to result.
*
* OS/Compiler : All
***/
char *strmvstr( char *out_str, const char *in_str, const char *target, const char *new_str )
{ char *ptr = out_str;
const char *ptr_new = new_str;
unsigned count;
for ( count = 0; *out_str = *in_str; out_str ++, in_str ++ )
if ( *out_str == *target ) { target ++; count ++;
if ( ! *target )
{ out_str -= count - 1;
target -= count;
count = 0;
while ( *out_str++ = *new_str++ );
new_str = ptr_new;
out_str --; out_str --;
}
}
else { target -= count;
out_str -= count;
in_str -= count;
count = 0;
}
return ptr;
}