#include<stdio.h>
char* find_ch(char *s, char v){
 
      while(*s != '\0'){
         if(*s == v)  return s;
          s++;
         }
      return NULL;
      
}
int main(){
    char s[128];
    char from, to;
    char *cptr;
    printf("string: ");
    scanf("%[^\n]s", s);
    printf("from: ");
    scanf(" %c", &from);
    
    printf("to: ");
    scanf(" %c", &to);
do{
    cptr = find_ch(s,from);
    *cptr = to; 
}while(cptr != NULL);
    printf("= %s\n", s);
    return 0;
}
เป็นโปรแกรม string replace ง่ายๆครับวนจนกว่า cptr จะเป็น NULL แต่ผมงงตอนรันมีerror ขึ้นมาเหมือนมันไม่ออกจาก do-while																															
						 
												
						
					
ช่วยดูโค้ดง่ายๆให้หน่อยครับ ไม่รุ้ติดตรงไหนจริงๆ
char* find_ch(char *s, char v){
while(*s != '\0'){
if(*s == v) return s;
s++;
}
return NULL;
}
int main(){
char s[128];
char from, to;
char *cptr;
printf("string: ");
scanf("%[^\n]s", s);
printf("from: ");
scanf(" %c", &from);
printf("to: ");
scanf(" %c", &to);
do{
cptr = find_ch(s,from);
*cptr = to;
}while(cptr != NULL);
printf("= %s\n", s);
return 0;
}
เป็นโปรแกรม string replace ง่ายๆครับวนจนกว่า cptr จะเป็น NULL แต่ผมงงตอนรันมีerror ขึ้นมาเหมือนมันไม่ออกจาก do-while