How can I convert numbers to strings (itoa() function)?

The C library function char *  itoa ( int value) converts the integer argument to string. This problem is about to write own itoa( ) function which has same argument parameter and return type. Following has a simplest logic to do so:


Algorithm is pretty simple, we divide number, collect remainder and convert it from integer value to ASCII by adding 48(ASCII value of zero) to integer value until number becomes zero.



Suggested Reading

  1. Write your own C program to implement the atoi() function
  2. Write a C program to reverse the string without using strrev() ?
  3. Convert decimal number into hexadecimal octal binary – single universal logic