Thread: int to char

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    77

    int to char

    is there and function to convent int to char array?

  2. #2
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    From Msdn:
    Convert an integer to a string.
    char *_itoa( int value, char *string, int radix );

    Example:

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    void main( void )
    {
       char buffer[20];
       int  i = 3445;
       long l = -344115L;
       unsigned long ul = 1234567890UL;
    
       _itoa( i, buffer, 10 );
       printf( "String of integer %d (radix 10): %s\n", i, buffer );
       _itoa( i, buffer, 16 );
       printf( "String of integer %d (radix 16): 0x%s\n", i, buffer );
       _itoa( i, buffer, 2  );
       printf( "String of integer %d (radix 2): %s\n", i, buffer );
    
       _ltoa( l, buffer, 16 );
       printf( "String of long int %ld (radix 16): 0x%s\n", l, 
                                                        buffer );
    
       _ultoa( ul, buffer, 16 );
       printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul,
                                                        buffer );
    }


    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Or sprintf() of course.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    77
    thanks TNT
    how to i use the sprintf();??

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    char buff[100];
    int num = 25;

    sprintf(buff, "%i", num);

    or even:

    sprintf(buff, "Num = %i", num);
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  3. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  4. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 04:24 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM