View Full Version : Conversion from unsigned char* to unsigned char
santosh.kumar
6th August 2007, 13:07
hi
in my application there is some error:cast from unsigned char* to unsigned char..
how to convert unsigned char* to unsigned char.
if anybody knows then reply
marcel
6th August 2007, 13:12
Well, that (unsigned char*) variable can be either a pointer to a single char or can be an array.
Depends on how it is allocated.
Anyway, you have to dereference it:
unsigned char chr = 23;
unsigned char* ptrChar = &chr; // pointer to a char
unsigned char* arrayChar = new char[20]; //an array
unsigned char valChar = *ptrChar; // now val char equals 23
unsigned char firstChar = *arrayChar; //now firstChar equals arrayChar[0].
So, everything depends on how the pointer was allocated.
BTW, I think you should have posted in the general programming forum.
Regards
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.