int to char

This is a discussion on int to char within the Windows Programming forums, part of the Platform Specific Boards category; is there and function to convent int to char array?...

  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,831
    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,669
    char buff[100];
    int num = 25;

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

    or even:

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



    ITSA
    Socket Library!

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, 03: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

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