Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy unsigned char array

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 *".

like image 787
user2829 Avatar asked Dec 22 '10 07:12

user2829


People also ask

How do I copy an unsigned character?

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*.

What is unsigned char array?

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.

How do you find the length of an unsigned char array?

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.


1 Answers

As indicated by its name, strcpy works on C string (which a unsigned char array is not).

You should consider memcpy.

like image 171
icecrime Avatar answered Sep 23 '22 21:09

icecrime