[Solved] copy from unsigned char to unsigned char


The reason for the warnings and error is that strncpy() accepts char * arguments, which is different from unsigned char *.

Assuming the two arrays in the structs are the same size simply do

 memcpy(d1.d.something, c->do_something, sizeof(d1.d.something));

If you can’t assume the two arrays are the same size, you’ll need to write code to check and limit the copying according. memcpy() is declared in <string.h>.

Note also that operator new is C++, even if the rest of what you are doing is vanilla C, as is my answer. In C, use malloc() – declared in <stdlib.h> – instead. And remember to release the memory (using free()) when done.

solved copy from unsigned char to unsigned char