|
-
January 5th, 2012, 12:14 PM
#1
how to refer to 2 dimensional array address
i have a problem here. I want to retrieve a data using memcpy.
code
////////////////////////////////////////////////////////////////////////////
unsigned char m_Data[256];
//m_Data = "Hello word";
unsigned char Dest[256];
int Data_Length = 11;
memcpy(Dest, m_Data +2, Data_Length);
///////////////////////////////////////////////////////////////////////////////
I have no problem with the above coding;
The problem is when my m_Data is 2 dimensional array, How do i do it?
code:
//////////////////////////////////////////////////////////////////////////////////
unsigned char m_Data[5][256];
//m_Data[0][256] = "Hello word";
//m_Data[1][256] = "Hell02";
//m_Data[2][256] = "Hello3";
unsigned char Dest[256];
int Data_Length = 11;
//the nRow will be known variable, which we iterate through
for(int nRow=0; nRow<5;nRow++)
memcpy(Dest, m_Data + (nRow*256) +2, Data_Length); //is this correct but i got crash here
//process here
////////////////////////////////////////////////////////////////////////////////////////////
Can someone help over here?
Thanks.
-
January 5th, 2012, 12:24 PM
#2
Re: how to refer to 2 dimensional array address
 Originally Posted by VbEndUser
//the nRow will be known variable, which we iterate through
for(int nRow=0; nRow<5;nRow++)
memcpy(Dest, m_Data + (nRow*256) +2, Data_Length); //is this correct but i got crash here
//process here
////////////////////////////////////////////////////////////////////////////////////////////
Can someone help over here?
Thanks.
Please use code tags when posting code.
Instead of doing pointer arithmetics yourself, you can use a more natural way:
Code:
mamcpy(Dest, &m_Data[nRow][2], Data_Length);
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
January 5th, 2012, 12:33 PM
#3
Re: how to refer to 2 dimensional array address
Dear D_Drmmr,
Thanks. it work just like what i want.
Forget how to input the quote into the code.
Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|