Results 1 to 6 of 6

Thread: Converting Integers to string

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Location
    Singapore
    Posts
    116
    I know this is a stupid question but i am quite new to C. How do I convert Integers to Array of Char???

    I know how to convert from an Array of Chars using the sscan
    YC Sim
    Teenage Programmer
    UIN 37903254



  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    You can use sprintf...

    Code:
    int       a;
    char      text[255];
    
    sprintf( text, "%d", a );

  3. #3
    Guest
    Also, you can look up a function called "itoa".

    [Edited by VirtuallyVB on 04-25-2000 at 09:00 PM]

  4. #4
    Junior Member
    Join Date
    Jan 2000
    Posts
    24

    Arrow

    you should try an explicit conversion, the reason for this over atoi or itoa is that you can use it on allmost every possible variable. how it works:

    Code:
    int y;
    CString z;
    
    y = 4;
    z = "2";
    
    if (blnItoA == TRUE)
    {
        z = (CString) y;
        // Now z == "4"
    }
    else
    {
        y = (int) z;
        // Now y == 2
    }
    that shouldn't be too tough...

    [Edited by Doomstar on 05-06-2000 at 01:35 PM]

    [Edited by Doomstar on 05-06-2000 at 01:36 PM]
    Doomstar
    http://surf.to/Doomstar

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827

    Wink I know this is annoying but...

    I'm sorry, I know some people hate it when people ask questions half way through a thread, but what's the difference between (int) and static_cast<int> ?

    In the C++ book I've got it says you should use the latter in C++, but doesn't really give a reason.
    Harry.

    "From one thing, know ten thousand things."

  6. #6
    Junior Member
    Join Date
    Jan 2000
    Posts
    24

    Talking don't be sorry...

    eh, well, i don't know the difference. in fact, i've never heard of static_cast<int>, but i'm not doing this for that long either. just use the (int) method, that way you're sure it works (i use it all the time in VC++)

    Doomstar
    http://surf.to/Doomstar

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