Casting

Started by
2 comments, last by HappyToLearnC 21 years, 6 months ago
I want to view a "long" in the MessageBox Here is a simple version of what I am doing : long xyz = 4; char* ok; ok = (char*)xyz; MessageBox(NULL,ok,"",MB_OK); When I execute I get the system error saying : The instruction at 0x77e13e49......ref memory could not be read" Could someone help? My best regards
God is the greatest
Advertisement
looks like you''re trying to dereference a null pointer...
this right here is your problem:

long xyz = 4;
char* ok;
ok = (char*)xyz;

you cant'' "cast" a long to a character array. you''ll have to
convert it using a manual algorithm (or one that''s already availible).
i know there''s an atoi() and itoa() function, perhaps there is an
ltoa() function as well, i''m too lazy to look it up

anyway, that''s where the problem is at, im sure you can take it
from here.

-eldee
;another space monkey;
[ Forced Evolution Studios ]

::evolve::

''In C we had to code our own bugs. In C++ we can inherit them.''

-eldee;another space monkey;[ Forced Evolution Studios ]
Your guess is right, there is
//char *_ltoa( long value, char *string, int radix );

I am experementing with it.

Thanks
God is the greatest
For concatenating/embedding variable-format data with/in strings in C, please use snprintf. In C++, use std::stringstream.

This topic is closed to new replies.

Advertisement