Convert integer to string: how to use itoa : Int Convert « Data Type « C / ANSI-C






Convert integer to string: how to use itoa



#include <stdio.h>
#include <stdlib.h>

int main ()
{
  int i;
  char str[33];

  printf ("Enter a number: ");
  scanf ("%d",&i);
  
  itoa (i,str,10);
  printf ("decimal: %s\n", str);
  
  itoa (i, str, 16);
  printf ("hexadecimal: %s\n", str);
  
  itoa (i, str, 2);
  printf ("binary: %s\n", str);
  
  return 0;
}

           
       








Related examples in the same category

1.A function to return a string representation of an integer with a given widthA function to return a string representation of an integer with a given width
2.A function to return a string representation of an integerA function to return a string representation of an integer
3.Convert an integer to words