473,383 Members | 1,929 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,383 software developers and data experts.

Appending rows to 2-dim arrays

I have a function that is returning a 2D array (declared using double pointers)
and I want to be able to append a row of data to the beginning and end of this
array without having to create a new 2D array and iterate through copy contents
from arrays into this new 2D array.

Example:

int ** someArray;
int * topRow;
int * bottomRow;

&someArray = someFun(); //returns 2D array.

/*
I want to...

someArray = topRow + someArray + bottomRow

*/

Thanks in advance,

Nathan Gilbert
--
"The life of a repoman is always intense."
Dec 7 '05 #1
1 1988
Nathan Gilbert wrote:
I have a function that is returning a 2D array (declared using double pointers)
and I want to be able to append a row of data to the beginning and end of this
array without having to create a new 2D array and iterate through copy contents
from arrays into this new 2D array.
There are no 2D arrays in C; there are arrays of arrays of T,
pointers to arrays of T, pointers to pointers of T and arrays
of pointers to T to emulate 2D arrays.

Do you understand the differences between the following declarations?
T arr[N][M];
T (*arr)[M];
T *arr[N];
T **arr;

You chose the fourth variant but could have chosen the third
as well.
So, you essentially have a pointer to storage containing
one or more pointers to T (or, in case 3, an array containing
pointers to T).
In order to change the order of your rows, or add to the rows,
you change the storage (array) containing the pointers to the
rows:

arr[0] is a pointer to the first row
.....
arr[I-1] is a pointer to the (I)th row

where I is the number of rows.
If arr points to sufficiently large storage (is a sufficiently
large array), say I + i == N, then you can add up to i rows by
copying pointers to the respective rows into a[i]...a[I+i-1].

In this case, you are responsible for the number of "columns"
per row.
If arr does not point to sufficiently large storage, then you
just have to reallocate the storage for the pointers to the rows
but not the rows themselves.
Example:

int ** someArray;
int * topRow;
int * bottomRow;

&someArray = someFun(); //returns 2D array.
You cannot change the storage location of a variable.

/*
I want to...

someArray = topRow + someArray + bottomRow

*/


See above. Inserting rows can be achieved by memmove()ing
the pointers to the rows which come after the new row(s)
"downwards" as is appropriate.

If you have implemented this and have some problems, just
ask -- but do show us your best shot at it.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Dec 7 '05 #2

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

Similar topics

4
by: bucket79 | last post by:
Hi is there anyway appending to dictionary? list has this feature >>>a = >>>a.append(1) >>>print a but dictionary can't
9
by: paul | last post by:
Hiya everyone, I have two tables in SQL 2000. I would like to append the contents of TableA to TableB. Table A has around 1.1 Million Records. Table B has around 1 Million Reocords. ...
1
by: oasd | last post by:
I'm having difficulty appending data. I have an import macro (using the Transferspreadsheet function) to import data from an excel spreadsheet (located in a USB attached to the pc) to an access...
3
by: MLH | last post by:
I have a query, qryAppend30DayOld260ies that attempts to append records to tblCorrespondence. When run, it can result in any of the following: appending no records, appending 1 record or appending...
2
by: shankar | last post by:
Hi all, This is the way to append the rows from one datatable into another with the same schema. Here Temp and Temp1 are the datatables For Each rows As DataRow In tempTable.Rows Temp1...
2
by: tony.collings | last post by:
I started a thread here : http://groups.google.co.uk/group/microsoft.public.cmserver.general/browse_thread/thread/29d63077144004a9/c3888efdcb7338f6?hl=en#c3888efdcb7338f6 About creating an Email...
13
by: Shwetabh | last post by:
Hi, I wanted to know if it is possible to do to append two tables into a third table. For example, consider these two tables Table 1...
2
by: Mark | last post by:
Hi - I'm looking for a code sample that will let me append a data table to a second master data table. You can assume that the tables' structures are identical. Seems like there should be a...
4
by: MGM | last post by:
Hello everyone, I once again have a problem :p I need to write a query to get the total amount of rows in a table. Problem is, the table name is dynamic and part of its value is stored in...
9
by: JWM81274 | last post by:
Is there a statement that will allow appending to the end of table when inserting new data? I use multiple "insert into table1(timestamp1,area1,value1,value2...)" to insert different area data with...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.