473,654 Members | 3,035 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 2327

"Dinçay Akçören" <di****@gmail.c omwrote in message
news:11******** **************@ y42g2000hsy.goo glegroups.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<heigh t;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...@btin ternet.comwrote :
"Dinçay Akçören" <din...@gmail.c omwrote in message

news:11******** **************@ y42g2000hsy.goo glegroups.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<heigh t;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.c omwrote in message
news:11******** **************@ r34g2000hsd.goo glegroups.com.. .
On 2 Eylül, 00:38, "Malcolm McLean" <regniz...@btin ternet.comwrote :
"Dinçay Akçören" <din...@gmail.c omwrote in message

news:11******** **************@ y42g2000hsy.goo glegroups.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<heigh t;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.c omwrote:
>On 2 Eylül, 00:38, "Malcolm McLean" <regniz...@btin ternet.comwrote :
>"Dinçay Akçören" <din...@gmail.c omwrote in message

news:11******* *************** @y42g2000hsy.go oglegroups.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<heig ht;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
16719
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
2919
by: paytam | last post by:
Hi all How can I define a dynamic matrix and pass it to a function?
8
2465
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 in the following way void (*f)(int);
5
9629
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 *(matrix+(i*columns)+j) ) { min = (matrix+(i*columns)+j);
1
2335
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: doSomething(&myA,...); I am not sure what to do with my ublas::matrix<doublemyB?
5
2797
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 this custom Matrix class to standard doubles Matrix (VC++) as I am passing it to some function that understands only the standard class.
12
3119
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: /***************************************************************/ #include <stdio.h>
0
2087
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 only thing needed for new users. I suggest you investigate a little bit more the next time you make such efforts, since this fact should be widely known among the users of the mentioned packages, see e.g. the huge warning at the numarray page:...
2
11659
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 width=\"200\" border=\"1\">"; foreach($matrix as $row =$rValue){ echo "<tr>"; foreach($rValue as $col =$cValue){ echo "<td>".$cValue."</td>"; }
0
8290
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8489
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8594
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7307
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4149
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2716
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 we have to send another system
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.