Solved

convert string to unsigned char *

Posted on 2002-06-19
2
589 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
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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.

821 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