Hello,
I am using the following str_replace function -:
Code:
char * str_replace(char *haystack,char *needle,char *rstr) {
size_t size=strlen(haystack)+1;
char *p[size+1];
char *ptrp=p;
char *newstr;
char *match;
char *replace;
int i,j;
if (p==NULL){
return(p);
}
newstr=haystack;
while (*newstr){
match=needle;
replace=rstr;
i=0;
while(*newstr && *match){
if(*newstr != *match){
*ptrp++=*newstr++;
match=needle;
i=0;
} else if(*newstr==*match){
*ptrp++=*newstr++;
match++;
i++;
}
}
if(i==(int)strlen(needle)){
j=0;
while(j<i){
ptrp--;
j++;
}
while(*replace){
*ptrp++=*replace++;
}
}
}
*ptrp='\0';
return(p);
}
Which works great, however, it does not seems to work if I want to remove "(" or ")" characters.
Any any ideas why?