Solved

convert string to unsigned char *

Posted on 2002-06-19
2
579 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now