C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-30-2009, 06:38 PM   #1
Registered User
 
Join Date: Jun 2009
Posts: 2
How to assign array of pointers to pointers, to content of static array?

Code:
char myData[90][3][50];   //90 rows, 3 columns, each block 50 chars long   
char **tableData[90] = {NULL};  

const char* text;
text = sqlite3_column_text(stmt, col_index);

text_lenght = strlen(text) + 1;         // add 1 to get null 
strncpy(myData[row_index][c_index], text, text_lenght);
//top line in a loop for all rows and each column    <--EDIT the assignment is outside the column loop within the row loop.


tableData[row_index] = myData[row_index]; <--?Warning on this line
I need tableData to correctly point to contents of myData but it's not happening.
The warning is:
Code:
 : warning C4047: '=' : 'char ** ' differs in levels of indirection from 'char (*)[50]'
During run time I can see myData properly populated how I expect. However, tableData is filled with bad pointers...

Any help is appreciated.
Thanks.

Last edited by tommy00b; 06-30-2009 at 07:13 PM.
tommy00b is offline   Reply With Quote
Old 06-30-2009, 06:55 PM   #2
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
You need to assign every element of tableData to point where you want it to point.
tabstop is offline   Reply With Quote
Old 06-30-2009, 07:12 PM   #3
Registered User
 
Join Date: Jun 2009
Posts: 2
Assigning each element runtime error

I moved the assignment inside the column loop that is within the row loop and I believe this assigns each element, correct?
Code:
tableData_gmti[row_index][c_index]= myData_gmti[row_index][c_index];
No warnings but now I have the runtime error:
Code:
Unhandled exception at 0x0040308e in GUI.exe: 0xC0000005: Access violation writing location 0x00000000.
tommy00b is offline   Reply With Quote
Old 06-30-2009, 07:29 PM   #4
Guest
 
Sebastiani's Avatar
 
Join Date: Aug 2001
Posts: 4,923
>> I need tableData to correctly point to contents of myData but it's not happening.

That will never work because 'myData' isn't an array of pointers.

Code:
int main( int argc, char** argv )
{
	const int 
		ROW_COUNT = 90, 
		COLUMN_COUNT = 25, 
		TEXT_LENGTH = 50;
	typedef char 
		text_block[TEXT_LENGTH];
	typedef text_block 
		columns[COLUMN_COUNT];
	typedef columns
		table[ROW_COUNT] ;
	table 
		myTable; 
	columns*	
		myColumns[ROW_COUNT] = {0};
	myColumns[8] = &myTable[15];
	strncpy(myTable[15][4], "foobar", TEXT_LENGTH - 1);
	puts((*myColumns[8])[4]); 	
}

Last edited by Sebastiani; 06-30-2009 at 07:36 PM. Reason: fixed confusing variable names
Sebastiani is offline   Reply With Quote
Old 07-01-2009, 01:53 PM   #5
Registered User
 
Join Date: Oct 2008
Location: TX
Posts: 1,262
Quote:
Originally Posted by tommy00b View Post
Code:
char myData[90][3][50];   //90 rows, 3 columns, each block 50 chars long   
char **tableData[90] = {NULL};  
...
tableData[row_index] = myData[row_index]; <--?Warning on this line
I need tableData to correctly point to contents of myData but it's not happening.
Perhaps something like
Code:
    char *a[50];
    char md[90][3][50];
    char **td[90] = {NULL};  
    a[0] = md[0][0];
    td[0] = &a[0];
itCbitC is offline   Reply With Quote
Reply

Tags
array, array-of-pointers, multi-dimensional, pointers, static

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Array of Pointers to Arrays Biozero C Programming 2 04-19-2007 02:31 PM
Array of struct pointers - Losing my mind drucillica C Programming 5 11-12-2005 11:50 PM
Unknown Memory Leak in Init() Function CodeHacker Windows Programming 3 07-09-2004 09:54 AM
simulate Grep command in Unix using C laxmi C Programming 6 05-10-2002 04:10 PM
Hi, could someone help me with arrays? goodn C Programming 20 10-18-2001 09:48 AM


All times are GMT -6. The time now is 11:37 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22