void HoanVi(char *a, char *b)
{
a = newchar[20];
b = newchar[20];
char *tmp = newchar[20];
strcpy(tmp,a);
strcpy(a,b);
strcpy(b,tmp);
}
That is wrong. The original arguments fed to the function are not modified to point to the new memory, so all memory allocated in this function is leaked. The original arguments already pointed to memory and there's no reason to allocate any in HoanVi.
Prefer to use strings.
Failing that, maybe something like the following.
1 2 3 4 5 6
void HoanVi(char *&a, char *&b)
{
char * tmp = a ;
a = b ;
b = temp ;
}
There's no reason to copy what's pointed to when we can just swap the pointers.