473,508 Members | 4,753 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get the length of unsigned char ?

1 New Member
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 ?
Apr 10 '12 #1
1 8065
Banfa
9,065 Recognized Expert Moderator Expert
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.
Apr 10 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
12230
by: Lee Crabtree | last post by:
I have a managed DLL that I've used to expose a C++ class. One of the functions in this class reads a line out of a file into a buffer of type "unsigned char*". Since all the data is just...
2
6976
by: Steven T. Hatton | last post by:
What is the best way to read data from a file into a fixed size array of unsigned char? This is a file holding only a SHA1 digest. What I would really like to do is initialize the ifstream with...
4
14952
by: cdrom205 | last post by:
static void MDString ( unsigned char *input) { MD5_CTX context; unsigned char digest; unsigned int len = sizeof(input);//strlen (const char*) md5.MD5Init (&context); md5.MD5Update...
5
7767
by: Stephen Cawood | last post by:
I'm trying to use a C++ .lib from C# (I tried the Interop group will no results). I have a working wrapper DLL (I can get back simple things like int), but I'm having issues dealing with an array...
2
3124
by: bubzilla | last post by:
hi got a little prob with data types. I´m reading data from a socket in to a unsigned char buf; . Now, lets say there are 60Bytes written into the array( but it is always different). Now i...
30
3227
by: Yevgen Muntyan | last post by:
Hey, Why is it legal to do union U {unsigned char u; int a;}; union U u; u.a = 1; u.u; I tried to find it in the standard, but I only found that
33
15459
by: Michael B Allen | last post by:
Hello, Early on I decided that all text (what most people call "strings" ) in my code would be unsigned char *. The reasoning is that the elements of these arrays are decidedly not signed. In...
5
17167
by: oliver.andrich | last post by:
Hi, can anybody with ctypes experience tell me, how to handle a C function that returns an unsigned char*? Obviously it is not a restype of c_char_p. Best regards, Oliver
2
1717
by: sansknowledge | last post by:
hello all i am new to this forum, i have some knowledge in c++. I am developing a win32 dll using vc++ 6.0 in winxp sp2 using a third party SDK my problem is the sdk is having a few structures 1)...
29
9925
by: Kenzogio | last post by:
Hi, I have a struct "allmsg" and him member : unsigned char card_number; //16 allmsg.card_number
0
7128
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7058
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.