How to convert a pointer to char*?
-
(I know this isn't really VC++)(Or is it?)(Anyway, it's not MFC) Example:
void main(){ int nInt; int *pInt; cout << /*help?!*/ }
I want to output the memory location of nInt. This location is saved into pInt :sigh:. The memory location is for instance 3031:3233, so pInt contains 0x30313233. If I would convert this (how) to char*, it'd say "0123". But what I want is 0x30313233 to be converted to a string saying "0x30313233". How is that possible? :confused: I know it is weird, but this is what I tried:void main(){ int nInt; int *pInt; cout << char*(void*(pInt)); }
//Excuse me for my bad English. :-O //---QUOTE--- // //"ERROR: Keyboard not present - Press F1 to continue" - Most BOIS chips -
(I know this isn't really VC++)(Or is it?)(Anyway, it's not MFC) Example:
void main(){ int nInt; int *pInt; cout << /*help?!*/ }
I want to output the memory location of nInt. This location is saved into pInt :sigh:. The memory location is for instance 3031:3233, so pInt contains 0x30313233. If I would convert this (how) to char*, it'd say "0123". But what I want is 0x30313233 to be converted to a string saying "0x30313233". How is that possible? :confused: I know it is weird, but this is what I tried:void main(){ int nInt; int *pInt; cout << char*(void*(pInt)); }
//Excuse me for my bad English. :-O //---QUOTE--- // //"ERROR: Keyboard not present - Press F1 to continue" - Most BOIS chips -
(I know this isn't really VC++)(Or is it?)(Anyway, it's not MFC) Example:
void main(){ int nInt; int *pInt; cout << /*help?!*/ }
I want to output the memory location of nInt. This location is saved into pInt :sigh:. The memory location is for instance 3031:3233, so pInt contains 0x30313233. If I would convert this (how) to char*, it'd say "0123". But what I want is 0x30313233 to be converted to a string saying "0x30313233". How is that possible? :confused: I know it is weird, but this is what I tried:void main(){ int nInt; int *pInt; cout << char*(void*(pInt)); }
//Excuse me for my bad English. :-O //---QUOTE--- // //"ERROR: Keyboard not present - Press F1 to continue" - Most BOIS chipstake a look at the function sprintf. it has the features that you are looking for and is part of the c runtime.
-
(I know this isn't really VC++)(Or is it?)(Anyway, it's not MFC) Example:
void main(){ int nInt; int *pInt; cout << /*help?!*/ }
I want to output the memory location of nInt. This location is saved into pInt :sigh:. The memory location is for instance 3031:3233, so pInt contains 0x30313233. If I would convert this (how) to char*, it'd say "0123". But what I want is 0x30313233 to be converted to a string saying "0x30313233". How is that possible? :confused: I know it is weird, but this is what I tried:void main(){ int nInt; int *pInt; cout << char*(void*(pInt)); }
//Excuse me for my bad English. :-O //---QUOTE--- // //"ERROR: Keyboard not present - Press F1 to continue" - Most BOIS chipsint nInt = 54321;
int *pInt = &nInt;
char buf [11]; // 8(number) + 2(0x) + 1(trailing null)
sprintf (buf, "0x%08x", (unsigned int)(pInt));
cout << buf;I must be in a good mood. Normally I'm not this helpful! Iain.
-
(I know this isn't really VC++)(Or is it?)(Anyway, it's not MFC) Example:
void main(){ int nInt; int *pInt; cout << /*help?!*/ }
I want to output the memory location of nInt. This location is saved into pInt :sigh:. The memory location is for instance 3031:3233, so pInt contains 0x30313233. If I would convert this (how) to char*, it'd say "0123". But what I want is 0x30313233 to be converted to a string saying "0x30313233". How is that possible? :confused: I know it is weird, but this is what I tried:void main(){ int nInt; int *pInt; cout << char*(void*(pInt)); }
//Excuse me for my bad English. :-O //---QUOTE--- // //"ERROR: Keyboard not present - Press F1 to continue" - Most BOIS chipsDaFrawg wrote: I want to output the memory location of nInt. This printed out the address for me:
int nNumber,
*pAddr;pAddr = &nNumber;
cout << pAddr << endl;If you want that address in a char* variable, use:
char addr[32];
sprintf(addr, "%#x", pAddr);
cout << addr << endl;
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
(I know this isn't really VC++)(Or is it?)(Anyway, it's not MFC) Example:
void main(){ int nInt; int *pInt; cout << /*help?!*/ }
I want to output the memory location of nInt. This location is saved into pInt :sigh:. The memory location is for instance 3031:3233, so pInt contains 0x30313233. If I would convert this (how) to char*, it'd say "0123". But what I want is 0x30313233 to be converted to a string saying "0x30313233". How is that possible? :confused: I know it is weird, but this is what I tried:void main(){ int nInt; int *pInt; cout << char*(void*(pInt)); }
//Excuse me for my bad English. :-O //---QUOTE--- // //"ERROR: Keyboard not present - Press F1 to continue" - Most BOIS chipsHow about this: #include void main() { int iVar; void *pVar = &iVar; std::cout << pVar << std::endl; } -------- There are 10 types of people in this world. Those who know binary and those who don't.