title: Using memcpy to copy arrays of different type
body: <p>I have read <a href="https://stackoverflow.com/questions/4944252/using-memcpy-to-copy-a-structure">this</a>, <a href="https://stackoverflow.com/questions/4932012/copying-one-structure-to-another">this</a> and <a href="https://stackoverflow.com/questions/4931123/copying-one-structure-to-another">this</a> but none of them answers what I like to know</p>
  
  <p>A set of PId's (3 bytes each) are returned from a hardware which is saved into a raw array (<code>buffer</code>). This device returns exactly 84 bytes. </p>
  
  <p>Then I need to copy these PIds to an array or arrays which is readable by API library for this device.</p>
  
  <p>Here is my code</p>
  
  <pre><code>#pragma pack (1)
  typedef unsigned char PId[3];
  typedef PId PIDs[28];
  
  int GetList(PId* plist){
  
      unsigned char buffer[84];
  
      //... Reads the data from hardware memory to buffer
      if (RunCMD(0xCD, &amp;buffer)){
          // buffer has the correct data now 'AAAA...'
  
          memcpy(&amp;plist,buffer, 84);
  
          printf("%02X%02X%02X\n", buffer[0], buffert[1], buffer[2]); 
          printf("%02X%02X%02X\n", buffer[3], buffer[4], buffer[5]); 
  
          return 0;
      } 
      return 1;
  }
  
  int main(void) {
      ...
  
      PId plist_a;
      GetList(&amp;plist_a);
  
      printf("%02X%02X%02X\n", plist_a[0][0], plist_a[0][1], plist_a[0][2]); 
      printf("%02X%02X%02X\n", plist_a[1][0], plist_a[1][1], plist_a[1][2]); 
      ...
  }
  </code></pre>
  
  <p>Somehow this code does not copy proper data to <code>PIDs</code> array. <code>buffer</code> have the proper data but after <code>memcpy</code>, <code>pids</code> does not have the same data.</p>
  
  <p>I know I'm doing something wrong but I can't find it.</p>
  
  <p>if it helps, I'm compiling my code with windows <code>GCC</code> for <code>ARM CPU</code></p>
  
  <p>EDIT: I apologize for confusing everyone, actually the code was working, however I missed a part of code. which I corrected.  <code>pids</code> is not of type <code>PIDs</code> it is a pointer to it.</p>