What would be the best way to copy unsigned char array to another?
For example:
unsigned char q[1000];
unsigned char p[1000];
strcpy (q,&p);
The above code does not work, it gives me error saying "cannot convert parameter 1 from unsigned char [1000] to char *".
As indicated by its name, strcpy works on C string (which a unsigned char array is not). You should consider memcpy . You can cast an unsigned char* to char*.
unsigned char is a character datatype where the variable consumes all the 8 bits of the memory and there is no sign bit (which is there in signed char). So it means that the range of unsigned char data type ranges from 0 to 255.
size_t size = sizeof(unsigned char*); If you're wanting to know how many elements does the pointer point to, that's a bit more complex. If this is a C style string then strlen or some variant is your best option.
As indicated by its name, strcpy
works on C string (which a unsigned char array is not).
You should consider memcpy
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With