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.
Re: how to refer to 2 dimensional array address
Quote:
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);
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.