> String replace function?

String replace function?

Posted at: 2014-12-18 
I want to write a function sreplace()

int sreplace(char newc,char oldc,char *s){

}

the return value must be the # of replacements made.

How can I write this function?

i would do it more like this

you do not need the temp pointer since C uses call by value.

Any changes to the pointer in your function [it has its own COPY] will not change the value of the pointer in the calling function.

include

int sreplace(char newc , char oldc , char *s){

int num;

for(num=0;*s;s++)

if(*s == oldc) {

*s = newc;

num++;

}

return num;

}

I want to write a function sreplace()

int sreplace(char newc,char oldc,char *s){

}

the return value must be the # of replacements made.

How can I write this function?