473,763 Members | 5,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creating multidimensiona l array at runtime and passing it as parameter to a function

hi
I want to make a program whose requirement are as following:

1) it has to create an NxN matrix after reading input (i.e. N) from a
file in the main() itself. [so runtime array initialization]
2) it has to send the array as a parameter to a function. [for
recursive calls]

condition 1 is not a problem when i use gmalloc for array
initialization. but for condition 2, i require that the function that
is called by the main(), it has to specify one of the
dimensions(beca use it is a multidimensiona l array) like function(int
array[][N])
any ideas?

--
Nitin Munjal

Sep 14 '07 #1
2 2583
Use a pointer to pass the variable. Make N a global var or pass the size as
an argument.
void function(int* arr, int size)
Sep 14 '07 #2
On Fri, 14 Sep 2007 03:40:18 -0000, nitinm
<im************ *****@gmail.com wrote:
>hi
I want to make a program whose requirement are as following:

1) it has to create an NxN matrix after reading input (i.e. N) from a
file in the main() itself. [so runtime array initialization]
2) it has to send the array as a parameter to a function. [for
recursive calls]

condition 1 is not a problem when i use gmalloc for array
What is gmalloc?
>initialization . but for condition 2, i require that the function that
is called by the main(), it has to specify one of the
dimensions(bec ause it is a multidimensiona l array) like function(int
array[][N])
Look at the faq (c-faq.com). It shows a method of defining a 2D array
using a pointer to pointer. If you use this, you don't need to
(actually cannot) specify the dimension as part of the array parameter
but you can (should) pass the dimension in a second integer argument.
Remove del for email
Sep 14 '07 #3

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

Similar topics

0
1368
by: Wihlelm Bierbaum | last post by:
I'm trying to make use of a certain method of a COM object that takes a multidimensional array as its sole parameter. Here's an example of the construction of said array: $cA = array(); $cA = new VARIANT($cDesc);Type Code $cA = new VARIANT($cLongDesc);Long Description $cA = new VARIANT('B'); $cA = new VARIANT($cPrice); $cA = new VARIANT('D');
8
5969
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1; this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ApplicantName", dataset.Tables.Columns.DataType, 50,
3
8199
by: Claire | last post by:
I have a multidimensional array defined as private double myArray = new double; The first column of the array contains X values, the other contains Y values I have a charting function defined as Add(Array XValues, Array YValues) How do I call the Add function, passing my array columns please. thanks
21
3314
by: vmsgman | last post by:
Here is a code sample ... int blah = ReadFile( defArray, defFileName, w, h); // Read File Contents into memory array and return for processing public int ReadFile( ref ushort nArray, string sFname, int w, int h) { FileStream fs = new FileStream(sFname, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); // Read data
21
4199
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if possible. The thing I am trying to do is to convert a double value to a string with 8 elements. 8 is fixed because of the files I work with. I will change this 8 character string with the one(8 character string) already in the file and so on. But I...
14
20410
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is passed also. I understand that this way of passing the array is by value and if the prototype is declared as foo(int *), it is by reference in which case the value if modified in the function will get reflected in the main function as well. I dont...
1
2153
by: Szabolcs Borsanyi | last post by:
The following code compiles with a warning message: passing arg 1 of `use_vector' from incompatible pointer type How can one correctly pass a multidimensional array (by reference) expressing that 'use_vector' is not meant to modify any of the elements. Thanks Szabolcs
5
3796
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);" I thought that it is very hard to memory map structure array. I need both read and write memory mapped file at both side of C# and C++.
1
1774
by: =?ISO-8859-1?Q?Norbert_P=FCrringer?= | last post by:
Hello, does anyone know, if it is possible (via reflection?) to instantiate a multidimensional array of a certain type, which is first known at run time? e.g. at runtime I have to create an array of type string. The type string is given by a variable of type Type. So the input parameter are Type, Cols and Rows.
0
10148
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
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
8822
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
7368
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
6643
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
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...
1
3917
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
3
2794
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.