Remove Duplicate

int remove_dup(char *str)
{
    int n = 0;
    char pre_c = str[0] + 1;    // let pre_c be different with str[0].
    char *c1, *c2;
 
    for (c1 = c2 = str; *c2 != '\0'; ) {
        if (*c2 != pre_c) {
            pre_c = *c2;
            *c1++ = *c2++;
        }
        else {
            c2++;
            n++;
        }
    }
    *c1 = '\0';
 
    return n;
}

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License