lost the leading 0, help

This is a discussion on lost the leading 0, help within the C++ Programming forums, part of the General Programming Boards category; Hi, I was hoping someone could help me find a 0 in a string. I'm trying to read a drive's ...

  1. #1
    Unregistered
    Guest

    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

  2. #2
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    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
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

  3. #3
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    Actually... I think that what I said doesn't make any sense at all

    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]
    Last edited by Mario; 05-26-2002 at 03:09 PM.
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Removing Leading & Trailing Whitespace
    By EvilGuru in forum C Programming
    Replies: 11
    Last Post: 12-01-2005, 02:59 PM
  2. I lost my laptop, DVD and money
    By Sang-drax in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-01-2004, 08:13 PM
  3. lost disk
    By Benzakhar in forum Linux Programming
    Replies: 7
    Last Post: 01-11-2004, 06:18 PM
  4. Lost ID number
    By ripper079 in forum C++ Programming
    Replies: 13
    Last Post: 10-04-2002, 01:51 PM
  5. API, LOST... help
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 03-13-2002, 03:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21