How to get the length of unsigned char ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pradiptadash
    New Member
    • Apr 2012
    • 1

    How to get the length of unsigned char ?

    How to get the length of unsigned char ?
    Example
    unsigned char uch[] ="welcome";
    size_t len = strlen(uch);
    its giving the error: "invalid conversion from ‘unsigned char*’ to ‘const char*"
    But its ok in case of char
    How to resolve that ?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    In C/C++ a character (and therefore a string) always uses char not unsigned char and therefore all the string manipulation functions like strlen are written to accept char *.

    The error is how you declare uch it should be declared

    char uch[] ="welcome";

    You could get rid of the error with a cast in the call to strlen but it would be better to declare uch with the right type in the first place.

    Comment

    Working...