P: n/a

I need to pass a two dimensional matrix to a function. Function gets
int ** but i cannot find appropriate input to function in main.
in main
mdelc(&ar1, 5, 5, 3);
function prototype:
void mdelc(int **ar1, int a, int b, int d)  
Share this Question
P: n/a

"Dinçay Akçören" <di****@gmail.comwrote in message
news:11**********************@y42g2000hsy.googlegr oups.com...
>I need to pass a two dimensional matrix to a function. Function gets
int ** but i cannot find appropriate input to function in main.
in main
mdelc(&ar1, 5, 5, 3);
function prototype:
void mdelc(int **ar1, int a, int b, int d)
int **ar;
ar = malloc(height * sizeof(int *));
for(i=0;i<height;i++)
ar[i] = malloc(width * sizeof(int));
now you can use
ar[y][x] = a; to set up the matrix values
call
mcdecl(ar, 5, 5, 3)
no &. ar is already an int **.
That's probably what the function mdecl is expecting. However it is not
possible to be certain without more information. It might have different
requirements for setting up the matrix.

Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm  
P: n/a

On 2 Eylül, 00:38, "Malcolm McLean" <regniz...@btinternet.comwrote:
"Dinçay Akçören" <din...@gmail.comwrote in message
news:11**********************@y42g2000hsy.googlegr oups.com...
I need to pass a two dimensional matrix to a function. Function gets
int ** but i cannot find appropriate input to function in main.
in main
mdelc(&ar1, 5, 5, 3);
function prototype:
void mdelc(int **ar1, int a, int b, int d)
int **ar;
ar = malloc(height * sizeof(int *));
for(i=0;i<height;i++)
ar[i] = malloc(width * sizeof(int));
now you can use
ar[y][x] = a; to set up the matrix values
call
mcdecl(ar, 5, 5, 3)
no &. ar is already an int **.
That's probably what the function mdecl is expecting. However it is not
possible to be certain without more information. It might have different
requirements for setting up the matrix.

Free games and programming goodies.http://www.personal.leeds.ac.uk/~bgy1mm
It doesn't work :(
Here is the function
void mdelr(int **arr, int a, int b, int d )
{
int i;
int j;
for (i=0; i<a; i++)
{
for(j=0; j<b; j++)
{
if (i >= d)
arr[i][j] = arr[i+1][j];
if (i == b1)
arr[i][j] = 0;
}
}
}
arr is a*b matris, row d is deleted, then remaining part is shifted to
left.  
P: n/a

"Dinçay Akçören" <di****@gmail.comwrote in message
news:11**********************@r34g2000hsd.googlegr oups.com...
On 2 Eylül, 00:38, "Malcolm McLean" <regniz...@btinternet.comwrote:
"Dinçay Akçören" <din...@gmail.comwrote in message
news:11**********************@y42g2000hsy.googlegr oups.com...
I need to pass a two dimensional matrix to a function. Function gets
int ** but i cannot find appropriate input to function in main.
in main
mdelc(&ar1, 5, 5, 3);
function prototype:
void mdelc(int **ar1, int a, int b, int d)
int **ar;
ar = malloc(height * sizeof(int *));
for(i=0;i<height;i++)
ar[i] = malloc(width * sizeof(int));
now you can use
ar[y][x] = a; to set up the matrix values
call
mcdecl(ar, 5, 5, 3)
no &. ar is already an int **.
That's probably what the function mdecl is expecting. However it is not
possible to be certain without more information. It might have different
requirements for setting up the matrix.

Free games and programming goodies.http://www.personal.leeds.ac.uk/~bgy1mm
It doesn't work :(
Here is the function
void mdelr(int **arr, int a, int b, int d )
{
int i;
int j;
for (i=0; i<a; i++)
{
for(j=0; j<b; j++)
{
if (i >= d)
arr[i][j] = arr[i+1][j];
if (i == b1)
arr[i][j] = 0;
}
}
}
arr is a*b matris, row d is deleted, then remaining part is shifted to
left.
>>>>>>>>>
It should work as I described.
arr is a pointer to a list of pointers. arr[i][j] accesses the i th row and
j th column of the matrix.
a and b have to be matrix height and width.  
P: n/a

On Sat, 01 Sep 2007 15:38:29 0700, "Dinçay Akçören"
<di****@gmail.comwrote:
>On 2 Eylül, 00:38, "Malcolm McLean" <regniz...@btinternet.comwrote:
>"Dinçay Akçören" <din...@gmail.comwrote in message
news:11**********************@y42g2000hsy.googleg roups.com...
>I need to pass a two dimensional matrix to a function. Function gets
int ** but i cannot find appropriate input to function in main.
in main
mdelc(&ar1, 5, 5, 3);
function prototype:
void mdelc(int **ar1, int a, int b, int d)
int **ar;
ar = malloc(height * sizeof(int *)); for(i=0;i<height;i++) ar[i] = malloc(width * sizeof(int));
now you can use
ar[y][x] = a; to set up the matrix values
call mcdecl(ar, 5, 5, 3) no &. ar is already an int **.
That's probably what the function mdecl is expecting. However it is not possible to be certain without more information. It might have different requirements for setting up the matrix.
 Free games and programming goodies.http://www.personal.leeds.ac.uk/~bgy1mm It doesn't work :(
Describe doesn't work. Are you getting compiler or linker errors? Are
the results different than what you expect? How.
>Here is the function
Show the code that calls the function. Preferably a compilable unit.
> void mdelr(int **arr, int a, int b, int d )
{
int i;
int j;
for (i=0; i<a; i++)
{
for(j=0; j<b; j++)
{
if (i >= d)
arr[i][j] = arr[i+1][j];
When i = b1, this invokes undefined behavior by access arr[b][j],
nonexistent elements of the array.
You could reverse these two if blocks and make the test on d an else
if.
if (i == b1)
arr[i][j] = 0;
}
} }
arr is a*b matris, row d is deleted, then remaining part is shifted to left.
Remove del for email   This discussion thread is closed Replies have been disabled for this discussion.   Question stats  viewed: 2039
 replies: 4
 date asked: Sep 1 '07
