-
lost the leading 0, help
Hi,
I was hoping someone could help me find a 0 in a string.
I'm trying to read a drive's serial number and store it as a string.
GetVolumeInformation(szHD,(LPTSTR)szVolNameBuff,
255,&dwSerial, &dwMFL,&dwSysFlags,
(LPTSTR)szFileSys,255);
char serial [20]="";
ultoa (dwSerial,serial,16);
The only problem is, I know that the serial number starts with a 0 and the proggy isn't storing that first 0.
TIA
-
I believe the number is there, but it's the way you are reading the var that hides it.
For C++ numbers that start with a 0 are considered in octal format.
You may want to cast dwSerial before passing it to ultoa
-
Actually... I think that what I said doesn't make any sense at all :rolleyes:
This is the prototype for ultoa
char* ultoa( unsigned long int value, char* buffer, int radix );
So basically you need to check if an implicit cast is happening when you pass dwSerial into ultoa.
[EDIT]
Grrr... the second time I edit this message...
I think i found your problem. You are using ultoa with base 16. If you want to convert dwSerial to a string that reads the serial number as is, you need to change the base to 10
[/EDIT]