Skip to content

Instantly share code, notes, and snippets.

@hjort
Created October 15, 2011 16:23
Show Gist options
  • Save hjort/1289806 to your computer and use it in GitHub Desktop.
Save hjort/1289806 to your computer and use it in GitHub Desktop.
void remover_letras_duplas(char *str);
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);
}
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