13

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

2
  • Are you sure you didn't mean to tag this question c++ and not c? There should be no problem using strcpy with unsigned char arrays (as long as they're null-terminated) in C. At worst an off-by-default warning. Commented Dec 22, 2010 at 8:03
  • 3
    It does not matter if it is C or C++, using the &operator is always a bug here. Commented Dec 22, 2010 at 8:37

1 Answer 1

27

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

You should consider memcpy.

Sign up to request clarification or add additional context in comments.

2 Comments

You can cast an unsigned char* to char*.
Can you provide a small example as I am having problems with copying an unsigned char variable to an unsigned char array using memcpy. passing argument 2 of ‘memcpy’ makes pointer from integer without a cast [-Wint-conversion]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.