Solved

convert string to unsigned char *

Posted on 2002-06-19
2
595 Views
Last Modified: 2012-05-04
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
Comment
Question by:NJordan72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
ID: 7093921
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
 
LVL 32

Expert Comment

by:jhance
ID: 7094081
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question