use pointers.
ansi c version --
Code:#include <stdio.h> #include <string.h> int main(int argc, char* argv[]) { char tmp[20]; char n[20]; strcpy(n,"0011233445566789"); memset(tmp,'\0',sizeof(tmp) ); // this avoids placing zero at end of string dedupe(tmp,n); printf("%s\n",tmp); return 0; } void dedupe(char *ret, char *in){ char *a,*b,*c; c=ret; a=in; b=a+1; while (*a!='\0'){ if(*a != *b) *c++=*a; a++; b++; } }




Reply With Quote