Hi everyone. I've written a search and replace routine in C99. I think it should work, but there is a point marked by the // where I want to restart the outer while loop. How do I do this?
Richard (TIA)
Code:
char *ptokens[][2] =
{
{ "Find this" , "Replace with this" } ,
{ "Another one" , "Here's the replacement." } ,
{ 0 , 0 }
} ;
int searchandreplace ( char* psource , char* pdestination )
{
while ( *psource != 0 )
{
int i = 0 ;
while ( ptokens [i][0] != 0 )
{
char* ptoken = strstr ( psource , ptokens [i][0] ) ;
if ( ptoken == psource )
{
strcpy ( pdestination , ptokens [i][1] ) ;
psource += strlen ( ptokens [i][0] ) ;
pdestination += strlen ( ptokens [i][1] ) ;
// start outer while again
}
else
i++ ;
}
*pdestination ++ = *psource ++ ;
}
*pdestination = 0 ;
return 0 ;
}