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

Prototype:

The prototype of the itoa() is:

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

Parameters:

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.

C


Download  Run Code

Output:

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

That’s all about itoa() implementation in C.

 
Related Post:

Implement atoi() function in C | Iterative & Recursive