Quote:
Originally posted by Adam Shapiro
Sample:
char *display;
long number=30001;
ltoa(number,display,5);
MessageBox(hWnd,display,"test",MB_OK);
-->CRASH!!
|
Adam,
Same problem. "char *display" allocates only enough memory to hold the pointer. "char" tells the compiler what kind of data the pointer points to (for type checking). "*" tells the compiler to allocate a 32-bit word for the pointer. "display" is a pointer to the pointer that the compiler/linker uses internally. ltoa() blindly uses the address contained in display as the destination address for the move. The problem is that display probably doesn't point to a valid chunk of memory that you can use. So at run-time, the memory managment hardware in the processor will catch this and return a trap #13 (a/k/a GP fault) to windows. This is a
very common mistake in c/c++ coding (yes, I've made this mistake more than a few times

).
Replace the "char *display;" line to "char display[sizeof(long)*8+1];" and it should work.
-Kevin