Message-ID: <390BFDEB.42A8D686@gtcom.net> From: Krogg X-Mailer: Mozilla 4.61 [en] (Win95; U) X-Accept-Language: en,en-US,en-GB,ja,af MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: Array swapping. References: <390B75BB DOT 621F846A AT gtcom DOT net> <390bf4ba DOT 51457508 AT news DOT cis DOT dfn DOT de> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 82 Date: Sun, 30 Apr 2000 05:33:32 -0400 NNTP-Posting-Host: 12.16.179.81 X-Trace: eagle.america.net 957087406 12.16.179.81 (Sun, 30 Apr 2000 05:36:46 EDT) NNTP-Posting-Date: Sun, 30 Apr 2000 05:36:46 EDT Organization: 24hoursupport.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Horst Kraemer wrote: > > On Sat, 29 Apr 2000 19:52:27 -0400, Krogg > 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... > > abc and cba don't point. Don't believe in fairy tales sine > grandmothers tell you. Arrays are _not_ pointers nor "constant" > pointers. They are arrays. They have meat. They are "data" like ints > or floats or structs. I know that,but the information about the array is stored SOMEWHERE,and therefore it should be able to be changed... > Therefore you can't "swap" statically allocated arrays without > swapping the data float by float. I bet you can,I dont know how yet,but i am drinking "Mountian Dew" and one day i will stay up long enough to prove it. > You have to define pointers which "correspond" to these arrays - in > the same ways as a pointer to char "corresponds" to a an array of > char. float[50][50] if an array of array of 50 floats. The > corresponding pointer type is the pointer type where the "outer array > type" is transformed to pointer, i.e. a pointer to array of 50 float: after reading that about 4 times,I an starting to get it. > float x[100][50]; > float y[100][50]; Is there some reason you used [100] instead of [50] as the first subscript? > float (*p1)[50]; > float (*p2)[50]; > > p1 = x; > p2 = y; > > Now you may use p1[3][5]|p2[3][5] in place of x[3][5]|y[3][5] in every > context. In order to "swap" you just swap the pointers: > > void *temp; > > temp = p1 ; p1 = p2 ; p2 = temp: Cool,I test it,and this is exactaly the automagic that i was looking for.You are truly a wizard. > Regards > Horst Thanks a lot,I been searching all day for a solution and though i have found some cool things to read,i never found a solution till i read your post.Thanks. BE cool, Krogg. -- |"""""<`.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____|