Created
October 15, 2011 16:23
-
-
Save hjort/1289806 to your computer and use it in GitHub Desktop.
void remover_letras_duplas(char *str);
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void | |
remover_letras_duplas(char *str) | |
{ | |
unsigned char cur, ult = 0; | |
char *ptr, *tmp, *ptmp; | |
ptr = str; | |
tmp = malloc(strlen(str) + 1); | |
ptmp = tmp; | |
while (*ptr) | |
{ | |
cur = *ptr; | |
if (cur != ult) | |
{ | |
*ptmp = cur; | |
ptmp++; | |
} | |
ult = cur; | |
ptr++; | |
} | |
*ptmp = '\0'; | |
strcpy(str, tmp); | |
free(tmp); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void | |
remover_letras_duplas(char *str) | |
{ | |
char *pstr = str, *pnew = str; | |
char last = *pstr; | |
while (*pstr) | |
{ | |
if (last != *pstr) | |
{ | |
pnew++; | |
last = *pstr; | |
*pnew = last; | |
} | |
pstr++; | |
} | |
pnew++; | |
*pnew = '\0'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment