[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 600
  • Last Modified:

convert string to unsigned char *

Hello-

I have a function that takes an 'unsigned char *' as a value.  This is data that I'm passing the functin to be worked on.  Unfortunetly prior to using the function I only have this data stored as a string (or char *).  

Is there a simple way to convert the strgin to an 'unsigned char *'?  Thanks.

0
NJordan72
Asked:
NJordan72
  • 2
1 Solution
 
jhanceCommented:
There is not much in the way of differences between a "char *" and an "unsigned char *", nor is there much difference between a "char" and an "unsigned char".

So unless you're doing something arithmetic with your strings (which is unusual, but possible) you can usually do the following safely:

char *p = "xyx";

unsigned char *u = (unsigned char *)p;

and then use u where you need the unsigned char.  Alternatively, you can just cast the char * to an unsigned char * with (unsigned char *).
0
 
jhanceCommented:
As always with a cast, be sure you understand what you're asking the compiler to do.  

In other words, make sure that such a conversion makes sense.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now