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.


 

Prototype:

The prototype of 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

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

 
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Loading...

Thanks for reading.

Please use our online compiler to post code in comments. To contribute, get in touch with us.
Like us? Please spread the word and help us grow. Happy coding 🙂
 



Leave a Reply

avatar
  Subscribe  
newest oldest most voted
Notify of
mike
Guest

very nice (y)