저는 c.it에서 부분 문자열 문제가 있습니다. 부분 문자열을 올바르게 변경하지 않았습니다. foo를 찾아 다른 것으로 바꾸어야하지만 it.it을 변경할 수 없습니다. 'o'부분 만 변경합니다. 제발 도와주세요. ..substring 오류를 대체합니다
#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;
}
char! = string. – duedl0r
함수는 하나의 문자 만 대치 할 수 있습니다. – Jon
[This (http://stackoverflow.com/questions/779875/what-is-the-function-to-replace-string-in-c)는 내 친구가 원하는 것이며, 개인이 아닌 문자열을 대체하려고합니다. 문자. – axiom