Message-ID: <390C2854.A93F5E85@earthlink.net> From: Martin Ambuhl Organization: Nocturnal Aviation X-Mailer: Mozilla 4.72 [en] (Win95; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: Array swapping. References: <390B75BB DOT 621F846A AT gtcom DOT net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 75 Date: Sun, 30 Apr 2000 12:33:27 GMT NNTP-Posting-Host: 63.23.128.60 X-Complaints-To: abuse AT earthlink DOT net X-Trace: newsread1.prod.itd.earthlink.net 957098007 63.23.128.60 (Sun, 30 Apr 2000 05:33:27 PDT) NNTP-Posting-Date: Sun, 30 Apr 2000 05:33:27 PDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Chris Mears wrote: > Uncompiled, untested. Obviously, since it doesn't work. But notice this: /* This is valid under both C99 and GNUC */ #include void swap(int m, int n, float a[m][n], float b[m][n]) { int i, j; float temp; /* moved to avoid possible non-optimized allocation problems */ for (i = 0; i < m; i++) for (j = 0; j < n; j++) { temp = a[i][j]; a[i][j] = b[i][j]; b[i][j] = temp; /* error in CM's code fixed */ } } float x[50][25] = { {1} }, y[50][25] = { { 2} }; int main(void) { printf("before swap, x[0][0] = %f, y[0][0] = %f\n", x[0][0], y[0][0]); swap(50, 25, x, y); printf("after swap, x[0][0] = %f, y[0][0] = %f\n", x[0][0], y[0][0]); return 0; } > > 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]; > } > } > } > > -- > Chris Mears > > ICQ: 36697123 -- Martin Ambuhl mambuhl AT earthlink DOT net What one knows is, in youth, of little moment; they know enough who know how to learn. - Henry Adams A thick skin is a gift from God. - Konrad Adenauer __________________________________________________________ Fight spam now! Get your free anti-spam service: http://www.brightmail.com