Sign in to follow this  
siliconsurfer

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

Recommended Posts

siliconsurfer    128
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
siliconsurfer    128
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this