Hello, I need some help..
I have to replace in s1, the string s2 with the string s3. I first found if s2 was a substring in s1, but i dont know what to do from here, I'm lost..
example: s1 = "It is a good day to die", s2 = "die", s3 = "pay up"
=> after execution s1 will be "it is a good day to pay up"
Here's the code for the function:
please help, I'm lacking ideas..
Thanks
I have to replace in s1, the string s2 with the string s3. I first found if s2 was a substring in s1, but i dont know what to do from here, I'm lost..
example: s1 = "It is a good day to die", s2 = "die", s3 = "pay up"
=> after execution s1 will be "it is a good day to pay up"
Here's the code for the function:
Code:
const char *String_Replace(const char *c, const char *sub, const char *s3)
{
if(!*sub)
return c;
for (;*c;c++)
{
if(*c==*sub)
{
const char *h,*n;
for(h=c,n=sub;*h&&*n;h++,n++)
{
if(*h!=*n)
break;
}
if(!*n)
return c;
}
}
return 0;
}
Thanks
Comment