Implement itoa() function in C

Write an efficient function to implement itoa() function in C. Standard itoa() function convert input number to its corresponding C-string using the specified base.



The prototype of itoa() is –

char* itoa(int value, char* buffer, int base);



value – Value to be converted to a string.
buffer – Array to store the resulting null-terminated string.
base – Numerical base used to represent the value as a string, between 2 and 36.


Return Value:

A pointer to the resulting null-terminated string, same as parameter buffer.


Download   Run Code


itoa(11184810, buffer, 16) = AAAAAA
itoa(-25, buffer, 10) = -25
itoa(64, buffer, 8) = 100
itoa(127, buffer, 2) = 1111111

Related Post: Implement atoi() function in C | Iterative & Recursive Implementation

Thanks for reading.

Please use ideone or C++ Shell or any other online compiler link to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂

Leave a Reply

newest oldest most voted
Notify of

very nice (y)