Search code examples
c++strcmpunsigned-charmemcmp

Read unsigned chars into string


I have an array of unsigned chars:

unsigned char buffer[BUFFER_SIZE];

I want to read in the first N unsigned chars from that array into a string however after looking at strncpy(), that seems to only take pointers to signed chars.

Should I be looking at memcpy()?


Solution

  • Not sure about the exact syntax but, if possible, you should use:

    reinterpret_cast<char *>(buffer[i]);
    

    Also see:

    Is there a good way to convert from unsigned char* to char*?