Results 1 to 10 of 10

Thread: Number to String

  1. #1

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    Number to String

    This has been asked millions of times before, I'm sure, but how do I turn a unsigned integer into a string, I'm using _utloa() function but it's not working. Am I doing something wrong?
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Just use the itoa function. See the FAQ for an example.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    whoops

    I made a huge mistake in my 1st post, I mean an unsigned long into a string. I use the _utloa() and I get '!!!!!!!!!' or similar returned.
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  4. #4
    Megatron
    Guest
    USe the sprintf() or wsprintf() functions.
    Code:
    int n = 45;
    LPSTR lpNum;
    wsprintf(lpNum, "%d", n);

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You need a real buffer, not just a pointer:
    Code:
    char pcBuf[10];
    sprintf(pcBuf, "%d", number);
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    I can't get it

    From this code

    Code:
    char    szSectors[10];
    sprintf(szSectors, "%i", 10);
    puts(szSectors);
    I'm getting ìììììììììììììììììììì in the szSectors
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I just tried that exact code and it printed "10"
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    hmm

    Are we talking Console applications or
    Windows Applications???

    Does it matter??
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  9. #9

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    Sorry posting heaps....

    ok. I'm getting 10ìììììììì now, is there a way to cut off the ììììììì's?

    edited:
    I'm being stupid now, I got it.
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  10. #10
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    try this...

    char szSectors[10];
    memset(szSectors, 0, 10);
    sprintf(szSectors, "%i", 10);
    puts(szSectors);

    or

    char szSectors[10]=NULL;
    sprintf(szSectors, "%i", 10);
    puts(szSectors);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width