i have a substring problem in c.it is not changing the substring properly.it has to find foo and replace it with other thing but it can not changes it.it just changes the 'o' part. please help out.
#include <stdio.h>
#include <string.h>
char *replace(char *s, char old, char newer)
{
char *p = &s[0];
while(*p)
{
if(*p == old)
*p = newer;
p++;
}
return s;
}
int main()
{
char mystr[250];
printf("enter ");
gets(mystr);
puts(replace(mystr, 'foo', 'bars'));
return 0;
}