Originally posted by Lynux-Penguin
no that works, thats essentially the same solution I had but I wanted to be able to switch the pointer's values (modify the pointers).
Yeah, that doesn't work. It's ok, I found ways around that hehe.
Thanks though.
-LC
To swap the pointers around, use something like this:
Code:
#include <stdio.h>
void swap (int **a, int **b)
{
int *c = *a;
*a = *b;
*b = c;
}
int main(void)
{
int i = 1;
int j = 2;
int *ip = &i;
int *jp = &j;
printf ("ip points to %p, which matches i (%p). \nThe value at the end of the pointer is %d\n", (void*)ip, (void*)&i, *ip);
printf ("\njp points to %p, which matches j (%p). \nThe value at the end of the pointer is %d\n", (void*)jp, (void*)&j, *jp);
swap (&ip, &jp);
puts ("\nAfter swapping the pointers...\n");
printf ("ip points to %p, which matches j (%p). \nThe value at the end of the pointer is %d\n", (void*)ip, (void*)&j, *ip);
printf ("\njp points to %p, which matches i (%p). \nThe value at the end of the pointer is %d\n", (void*)jp, (void*)&i, *jp);
return(0);
}
/*
Output
ip points to 0012FF80, which matches i (0012FF80).
The value at the end of the pointer is 1
jp points to 0012FF84, which matches j (0012FF84).
The value at the end of the pointer is 2
After swapping the pointers...
ip points to 0012FF84, which matches j (0012FF84).
The value at the end of the pointer is 2
jp points to 0012FF80, which matches i (0012FF80).
The value at the end of the pointer is 1
*/