top | item 21991031

(no title)

CHsurfer | 6 years 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")

discuss

order

skocznymroczny|6 years ago

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.

ithinkso|6 years ago

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