Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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")



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 :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: