Type conversion
-
Hi all, am writing a program in embedded VC++... am new to programming so i need some help with a little thing.. i have a form that the user will input a hex value (memory address) and my program will copy this value to a pointer.. but it just isn't working. here is my code DWORD *pDUMMY; TCHAR sztTmp[10]; GetDlgItemText(hwndDlg, IDC_EDT_NAME,sztTmp, 10); pDUMMY=(DWORD *)(sztTmp); //this line needs some editing example: user enters 0x8fff42a2 should equal pDUMMY = (DWORD *) (0x8fff42a2) sorry for the stupid question.. i'm helpless...
-
Hi all, am writing a program in embedded VC++... am new to programming so i need some help with a little thing.. i have a form that the user will input a hex value (memory address) and my program will copy this value to a pointer.. but it just isn't working. here is my code DWORD *pDUMMY; TCHAR sztTmp[10]; GetDlgItemText(hwndDlg, IDC_EDT_NAME,sztTmp, 10); pDUMMY=(DWORD *)(sztTmp); //this line needs some editing example: user enters 0x8fff42a2 should equal pDUMMY = (DWORD *) (0x8fff42a2) sorry for the stupid question.. i'm helpless...
pDUMMY = _tcstoul( sztTmp, NULL, 0 ); passing the 0 means that if the string starts with 0x then it's assumed to be hex, if it starts with 0 and not an x then it's assumed to be octal, and otherwise it's assumed to be a decimal value so it's rather flexible. you can pass 16 instead if you always assume the value is hexadecimal.
-
pDUMMY = _tcstoul( sztTmp, NULL, 0 ); passing the 0 means that if the string starts with 0x then it's assumed to be hex, if it starts with 0 and not an x then it's assumed to be octal, and otherwise it's assumed to be a decimal value so it's rather flexible. you can pass 16 instead if you always assume the value is hexadecimal.
Rick York wrote:
pDUMMY = _tcstoul( sztTmp, NULL, 0 );
actually you have to do
*pDUMMY = _tcstoul( sztTmp, NULL, 0 );
note the pointer dereference operator. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Rick York wrote:
pDUMMY = _tcstoul( sztTmp, NULL, 0 );
actually you have to do
*pDUMMY = _tcstoul( sztTmp, NULL, 0 );
note the pointer dereference operator. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
It works.... haha!... thank you guys, you saved me!!!