Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting string to unsigned char

Status
Not open for further replies.

paul51

Programmer
May 19, 2000
38
0
0
US
I am trying to convert a string to an unsigned char.

The code follows.

char temp[100];
strcpy(temp,"1234");
unsigned char uc[100];
strcpy(uc,temp);
//error C2664: 'strcpy' : cannot convert parameter 1 from 'unsigned char [100]' to 'char *'

Any help would be greatly appreciated.
Thanks.
 
Thanks for the idea. I still get an error.

'static_cast' : cannot convert from 'unsigned char [100]' to 'char *'
 
I guess you'll have to use reinterpret_cast then.
 
Why not just use memcpy - then you don't need to cast anything.
 
static_cast, reinterpret_cast.... why use these for basic types?

Code:
strcpy((char*) uc, temp);

------------------
When you do it, do it right.
 
dEVooXiAm said:
static_cast, reinterpret_cast.... why use these for basic types?

Because they're more explicit about what you wanted to do, and it's easier to search for occurrences of that type of cast in code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top