473,503 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Matrix as an argument

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)

Sep 1 '07 #1
4 2315

"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

Sep 1 '07 #2
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 == b-1)
arr[i][j] = 0;
}
}
}

arr is a*b matris, row d is deleted, then remaining part is shifted to
left.

Sep 1 '07 #3

"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 == b-1)
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.
Sep 2 '07 #4
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 = b-1, this invokes undefined behavior by access arr[b][j],
non-existent elements of the array.

You could reverse these two if blocks and make the test on d an else
if.
if (i == b-1)
arr[i][j] = 0;
}
}
}

arr is a*b matris, row d is deleted, then remaining part is shifted to
left.

Remove del for email
Sep 3 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
16700
by: Charulatha Kalluri | last post by:
Hi, I'm implementing a Matrix class, as part of a project. This is the interface I've designed: class Matrix( )
3
2914
by: paytam | last post by:
Hi all How can I define a dynamic matrix and pass it to a function?
8
2455
by: Klaas Vantournhout | last post by:
Hi all, I'm in need of a matrix of function pointers, and to be honest. No 'nice' solution has been found yet on that big big internet. It is possible to declare a matrix of function pointers...
5
9616
by: Anolethron | last post by:
Wrong one: void minptr (int *matrix, int rows, int columns,int *min){ int i=0,j=0; *min=*matrix; //!!!!!!!!!!!!!!!!! for (i=0; i < rows; i++) { for (j=0; j < columns; j++) { if( *min...
1
2320
by: sanjeev.p3 | last post by:
I need to pass ublas::matrix data to a legacy C API which expects input in the form: void doSomething(double* data,...); If I have a std::vector<doublemyA this is easy. I do: ...
5
2790
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi, I developed a custom Matrix class derived from custom VC++ doubles Array class derived from a RealArray which is defined as: typedef CArray<double,doubleRealArray; Now I need to convert...
12
3100
by: Nezhate | last post by:
Hi all, Is there any way to print a matrix's elements using a simple printf ? what I want as result is for example: if mat ={0,1,2,3} result must be: "0123". I tried this code: ...
0
2072
by: Bas | last post by:
On Sep 22, 10:02 am, Al Kabaila <akaba...@pcug.org.auwrote: That argument might have been valid 3 years ago, but as already said by others, Numeric and Numarray are deprecated. Numpy should be the...
2
11645
by: serave | last post by:
Hi, i need some help printing a mutlidimensional array, i can do it for square Matriz MxM but i need to print an MXN matrix. here is my code : function printMatrix($matrix){ echo "<table...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.