title: memcpy to concat smaller arrays into bigger ones
body: <p>I am trying to figure out how to take small bits of data and combine it into a bigger array using memcopy. This is in c and not c++.</p>
  
  <pre><code>memcpy(void* dest, void* src, size_t n);
  </code></pre>
  
  <p>so I set a dest buffer a src buffer and the amount of data to copy.</p>
  
  <p>I've been trying but I am not getting the results that I expect. I just want to take 8 copies of the 4 value float array and pack it into the one 32 value float array.</p>
  
  <pre><code>float test[32];
  float tmp[4] = {9, 8, 7, 6};
  printf("size of tmp:%lu sizeof tmp/ tmp[0]:%lu\n", sizeof(tmp),
         (sizeof(tmp) / sizeof(tmp[0])));
  printf("============\n");
  </code></pre>
  
  <p>doing the printf to check the sizes, 4 float is 16 and the size of 1 float is 4, just sanity checks on my part.</p>
  
  <pre><code>memcpy(test, tmp + (sizeof(tmp)*0), sizeof(tmp));  //this is the initial offset at 0
  memcpy(test + (sizeof(tmp)*1), tmp, sizeof(tmp)); //this should copy to the test buffer plus and offset of 16 bytes
  memcpy(test + (sizeof(tmp)*2), tmp, sizeof(tmp)); //etc
  
  for (int i = 0; i &lt; 32; i++) {
      printf("%f ", test[i]);
      if (i &gt; 1 &amp;&amp; i % 4 == 0) printf("\n");
  }
  </code></pre>
  
  <p>it seems like only the initial 4 bytes are copied and all the subsequent ones fail.</p>
  
  <p>The reason for using offsets and such is that I want to generalize this but even writing out such a simple use case of just copying 16 byte offset it doesn't work.</p>
  
  <p>I get this printout:</p>
  
  <pre><code>size of tmp:16 sizeof tmp/ tmp[0]:4
  ============
  9.000000 8.000000 7.000000 6.000000 0.000000
  0.000000 0.000000 0.000000 1602397014491231940111075790290944.000000
  0.000000 -6544621971295550046208.000000 0.000000 0.000000
  0.000000 1602345021009581954139530027073536.000000 0.000000 9.000000
  8.000000 7.000000 6.000000 0.000000
  0.000000 -1796536614528950701815653974964961280.000000 0.000000 0.000000
  0.000000 0.000000 0.000000 1602345021009581954139530027073536.000000
  </code></pre>
  
  <p>now i can understand the random numbers means the memory hasn't be properly initialized but I can't figure out why the memcpy isn't working as expected.</p>