Hacker News new | ask | show | jobs
by CHsurfer 2347 days 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")

1 comments

Here'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.

No it didn't and it doesn't :)