6 ms·
char* convert(char* str, char find, char replace){ char *current_pos = strchr(str,find); while (current_pos){ *current_pos = replace;
by CHsurfer 7y ago
char* convert(char* str, char find, char replace){
char *current_pos = strchr(str,find);
while (current_pos){
*current_pos = replace;
current_pos = strchr(current_pos,find);
}
return str;
}
convert("H264", "4", "5")
- skocznymroczny 7y agoHere's an optimized version: char* convert(char* str) { str[3] = "5"; return str; } I tried it with your testcase and it worked, so it passes 100% of the tests I've ran.
- ithinkso 7y agoNo it didn't and it doesn't :)