Mail Archives: djgpp/2000/05/02/11:05:24
Krogg <krogg DOT no DOT to DOT spam AT gtcom DOT net> wrote:
> I got 2 arrays of same type/size.
> float abc[50][50];
> float cba[50][50];
> how can i "swap" them?
> so that abc[x][y] will now point to cba[x][y] and
> vice versa...
You want them to 'point', so obviously you need pointers. :-)
Now, some keep saying that arrays are the same as pointers, in
C. That's not true, and this is exactly one of the cases where the
difference becomes important. You either have to convert to
float (*abc)[50];
float (*cba)[50];
and use 'malloc' to allocate them, or you can
float real_abc[50][50];
float real_cba[50][50];
float (*abc)[50] = real_abc;
float (*cba)[50] = real_cba;
In both cases the swap then works like this:
{
float (*abc)[50] temp = abc;
abc = cba;
cba = temp;
}
A side note: this is not really on-topic for this newsgroup. It's a
basic C question, and thus should be asked to comp.lang.c or a similar
group.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -