itoa() integer to string conversion - C-Tutorial

Latest

Saturday, 8 October 2016

itoa() integer to string conversion

itoa() function:           atoi() function converts an integer value into a string.  The general format of the itoa() function is:


                      
                             Syntax:           char *  itoa(int  , char[] , int);
Where,
  •             First argument is an integer value used for conversion.
  •             Second argument is a string used to store the conversion value.
  •             Third argument is an integer value that represents format of conversion such as decimal, octal and hexa-decimal format.


/* itoa example */
    #include <stdio.h>
      #include <stdlib.h>

          main ()
            {
                  int i;
                    char buffer [33];
                      printf ("Enter a number: ");
                        scanf ("%d",&i);
                          itoa (i,buffer,10);
                            printf ("decimal: %s\n",buffer);
                              itoa (i,buffer,16);
                                printf ("hexadecimal: %s\n",buffer);
                                  itoa (i,buffer,2);
                                    printf ("binary: %s\n",buffer);
                                  }

                                  No comments:

                                  Post a Comment