473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Creating Dynamic 2D Arrays

#define MAX_TABLE = 1024;
BYTE* dynamic1D = new BYTE[SIZE];

later..

i want to create a dynamic 2d ARRAY like this:

[0][<dynamic1D[1]>]
[0][<dynamic1D[2]>]
[0][<dynamic1D[3]>]
.....
[0][<dynamic1D[SIZE]>]

[1][<dynamic1D[1]>]
[1][<dynamic1D[2]>]
[1][<dynamic1D[3]>]
.....
[1][<dynamic1D[SIZE]>]

.....
[MAX_TABLE][<dynamic1D[1]>]
[MAX_TABLE][<dynamic1D[2]>]
[MAX_TABLE][<dynamic1D[3]>]
.....
[MAX_TABLE][<dynamic1D[SIZE]>]

Thx,
!MKD! ('',)!

Dec 15 '05 #1
2 5398
monkeydragon schrieb:
#define MAX_TABLE = 1024;
BYTE* dynamic1D = new BYTE[SIZE];

later..

i want to create a dynamic 2d ARRAY like this:

Hi,
int main () {
int rows=10,cols=10;
int** mat = new int*[rows];
for (int i=0; i<rows; i++) mat[i]=new int [cols];

//access example:
mat[2][3]=15;

//dont forget to free it after its not required any more
for (int i=0; i<rows; i++) delete[] mat[i];
delete[] mat;

return 0;
}

Another way would be using STL:

vector <vector<int>> mat (rows,vector<int>(cols));
mat[2][3]=15;

regards marcas
Dec 15 '05 #2
marcas wrote:
monkeydragon schrieb:
#define MAX_TABLE = 1024;
BYTE* dynamic1D = new BYTE[SIZE];

later..

i want to create a dynamic 2d ARRAY like this:

Hi,
int main () {
int rows=10,cols=10;
int** mat = new int*[rows];
for (int i=0; i<rows; i++) mat[i]=new int [cols];

//access example:
mat[2][3]=15;

//dont forget to free it after its not required any more
for (int i=0; i<rows; i++) delete[] mat[i];
delete[] mat;

return 0;
}

Another way would be using STL:

vector <vector<int>> mat (rows,vector<int>(cols));
mat[2][3]=15;

regards marcas


I recommend the vector method, but be carefull to add a space betwee >>
Should be the following:
vector <vector<int> > mat (rows, vector<int>(cols));

With the current C++ standard, you'll get a compile error if you don't
put the space between > >. They are considering changing this in a
future version of the standard.

Also take a look at the following links for other methods for creating
a dynamic 2D array:
http://code.axter.com/dynamic_2d_array.h
http://www.codeguru.com/forum/showthread.php?t=231046
http://www.codeguru.com/forum/showth...hreadid=297838

C-Style compatible method:
http://code.axter.com/allocate2darray.h
http://code.axter.com/allocate2darray.c

Dec 15 '05 #3

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

Similar topics

3
by: meyousikmann | last post by:
The following code just sets up and fills a dynamic array of integers. #include <cstdlib> int main() { int* intArray = NULL; int count; count = 20;
4
by: Scott Lyons | last post by:
Hey all, Can someone help me figure out how to pass a dynamic array into a function? Its been giving me some trouble, and my textbook of course doesnt cover the issue. Its probably something...
3
by: genc ymeri | last post by:
Hi, What can I use in C# for dynamic arrays ???? I have some records (struts in ..Net) and want to store them in a dynamic "arrays" or object list. I noticed the in C# arrays' length can't be...
2
by: stealth_spoof | last post by:
Hi People wondering if anyone can help me with a problem I'm having I'm trying to create an array with an unspecified length, the length is based on the result i get from another task in the code...
4
by: learnfpga | last post by:
Here is a little code I wrote to add the numbers input by the user.....I was wondering if its possible to have the same functionality without using dynamic arrays.....just curious..... ...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
4
by: hobbes992 | last post by:
Howdy folks, I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level directory file system. No files have to be added or...
11
by: Matthew Wells | last post by:
Hello. I have figured out how to create an instance of an object only knowing the type by string. string sName = "MyClassName"; Type t = Type.GetType(sName); Object objNew =...
4
by: Sunny | last post by:
Hi, Is there a way in javascript to create Dynamic arrays or arrays on fly. Something Like: var "ptsgN"+sd = new Array(); Here sd is incrementing by 1. I have lots of data that I am...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.