Write a function having this prototype:
int replace(char *s,char c1,char c2); Have the function replace every occurrence of c1 in the string s with c2, ad have the function return the number of replacements it makes.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
int replace(char * str, char c1, char c2)
{
int count = 0;
while (*str) // while not at end of string
{
if (*str == c1)
{
*str = c2;
count++;
} str++; // advance to next character
}
return count;
}