I made a code to swap two strings:
void swap (char *a, char *b)
{
char *t = a;
a = b;
b = t;
}
int main()
{
char * strings[2];
strings [0] = "luck!";
strings [1] = "good ";
swap (strings[0], strings[1]);
printf( "%s %s\n",strings[0], strings[1]);
return 0;
}
And it fails. What i have trouble understanding is when i call swap()
i pass two pointers. Both pointers point to the first character of their assigned arrays. I then created a temporary pointer inside the function and perform basic switch. What is flawed here? I really want to understand why this approach is wrong?