What is the use of unsigned char stream.
If I am having an unsigned character stream as below , how can i print the values inside that stream.
For an ordinary character stream or string i can print it using %s, but what about this.
Thanks in advance.
unsigned char *ptr ="(some value)"
When it comes to string handling, there is no notable difference between unsigned char and plain char. The latter can be either signed or unsigned, it is implementation-defined. However, all symbol tables always have positive index. So when you are dealing with strings, you can always safely cast between unsigned char and char. (Pointer casts between the two types are formally poorly defined behavior by the standard, but in reality, it will always work on any system ever made.)
Thus printf("%s", ptr); will work fine.
An unsigned char array usually represents raw byte data and if you want to output that as a string by using %s, you'll probably get gibberish characters, that'll be of no meaning to you.
If you really wish to see the values, then i recommend conversion of a single byte to short and then output it with a %i.
Just my opinion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With