CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2004
    Posts
    61

    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.

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: how to refer to 2 dimensional array address

    Quote Originally Posted by VbEndUser View Post
    //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

  3. #3
    Join Date
    Dec 2004
    Posts
    61

    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
  •  





Click Here to Expand Forum to Full Width

Featured