Thread: Convert int to string??

  1. #1
    Registered User
    Join Date
    Apr 2010
    Location
    kingston jamaica
    Posts
    28

    Convert int to string??

    How do you convert a integer to a string?

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Look up the sprintf function.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Location
    kingston jamaica
    Posts
    28
    ile look into it

  4. #4
    Registered User
    Join Date
    Apr 2010
    Location
    kingston jamaica
    Posts
    28
    Thanks whiteflags. Works great

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    And since we're all bored...
    Code:
    void inttostr( int i, char *s )
    {
        if( s )
        {
            int d = i;
        
            if( i < 0 )
            {
                *s++ = '-';
                i = 0 - i;
            }
            for( d = i; d; s++, d/=10 );
            *s-- = '\0';
            for( d = i; d; d /= 10 )
                *s-- = '0' + (d % 10);
        }
    }
    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to combine these working parts??
    By transgalactic2 in forum C Programming
    Replies: 0
    Last Post: 02-01-2009, 08:19 AM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM