passing *char parameters by reference
Jeff Aguilera
jeffa at hpmwtd.HP.COM
Fri Aug 11 08:51:28 AEST 1989
>> Would someone be kind enough to tell me why this program fails?
Because it is wrong. Instead try
swap(x,y)
register char **x, **y;
{
register char *temp;
temp = (*x); /* parentheses added for clarity */
(*x) = (*y);
(*y) = temp;
}
main()
{
char *a="aaaa";
char *b="bbbb";
swap( &a, &b ); /* Note that &(char*) produces a (char**) */
printf( " a = %s\t b = %s\n", a, b);
}
More information about the Comp.lang.c
mailing list