Mail Archives: djgpp/2000/04/30/09:25:53
Chris Mears wrote:
> Uncompiled, untested.
Obviously, since it doesn't work. But notice this:
/* This is valid under both C99 and GNUC */
#include <stdio.h>
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
- Raw text -