Jump to content
  • Advertisement
Sign in to follow this  
siliconsurfer

How to compare an const unsigned char * with a char *

This topic is 4702 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I call a method which returns a conts unsigned char *, now I want to compare that to a string. I know for a char * I can just do strcmp(char *, "string"); But this gives errors, I presume because it's unsigned. Does anyone know how I could compare the two?? Thanks

Share this post


Link to post
Share on other sites
Advertisement
By string, do you mean std::string? What errors is it giving you? Could you post the code that has the errors?

Share this post


Link to post
Share on other sites
For anyone who may be interested, I found out how to cast the const unsigned char * to a const char *, thus I could compare two char * variables using strcmp.

//First I call my method which returns the unsigned char *
const unsigned char *rspValue = rsp->getValue();

//Next I compare the two, using reinterpret_cast to recast the type
if(strcmp(reinterpret_cast<const char *>(rspValue), "11") == 0){
//Do some stuff here
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!