delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/30/09:44:33

From: Joseph Rose <jorose AT mail DOT gis DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Array swapping.
Date: Sun, 30 Apr 2000 09:42:59 -0400
Organization: Posted via Supernews, http://www.supernews.com
Lines: 76
Message-ID: <390C3863.83DC45CE@pop.gis.net>
References: <390B75BB DOT 621F846A AT gtcom DOT net> <be7ngssbe6fnhur5if8j27a3ct35gpj2e9 AT 4ax DOT com> <390BAB86 DOT 7C1EF855 AT gtcom DOT net> <390BBCF8 DOT 27D2D2AC AT pop DOT gis DOT net>
X-Complaints-To: newsabuse AT supernews DOT com
X-Mailer: Mozilla 4.7 [en]C-NECCK (Win98; I)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

It is supposed to swap the pointers.

Joseph Rose wrote:

> Try:
>
> void Swap (void* A, void* B)
> {
>     void* i=A
>     A=B
>     B=i
>     return;
> }
>
> I am still new to C++: & accesses the variable to which a pointer
> points, right?  I haven't tested this: I don't know that void* can point
> to anything, or even if this works.
>
> BTW, I looked through the Visual C++ etexts, and found a swap function
> which seems to swap anything.  I don't remember what you have to do to
> use it, though, or even if DJGPP has it.
>
> Krogg wrote:
>
> > Chris Mears wrote:
> > >
> > > On Sat, 29 Apr 2000 19:52:27 -0400, that hoopy frood 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...
> > > >
> > > >I dont care if it is portable,just so long as
> > > >it works and can be done over and over.....
> > >
> > > Uncompiled, untested.
> > >
> > > void swap(float a[50][50], float b[50][50])
> > > {
> > >     int i;
> > >     int j;
> > >
> > >     for (i = 0 ; i < 50 ; i++)
> > >     {
> > >         for (j = 0 ; j < 50 ; j++)
> > >         {
> > >             float temp = a[i][j];
> > >             a[i][j] = b[i][j];
> > >             b[i][j] = a[i][j];
> > >         }
> > >     }
> > > }
> > >
> >
> > Thats not what i am looking for...
> > I want to swap witch array the array name points to in place.
> >
> > --
> >
> > |"""""<`.THE PRINCE ,'>"""""""""""""""""""""""""""""""""""|
> > |      `.`/""""""\,','            my sig is too big,      |
> > |SEE HIS (  /   \ \' SEE HIS      but its really cool.    |
> > | FACE    \/<> <>\/   SMILE                               |
> > |         /   W   \          Visit my ascii art site:     |
> > |       ,'\_|||||_/`.  http://www.gtcom.net/~krogg/ascii/ |
> > |     ,','   |||   `.`.     krogg DOT no DOT to DOT spam AT gtcom DOT net    |
> > |____<,' TIME TO DIE `.>____Remove no.to.spam to reply____|

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019