Pages

Convert integer to string (char * or char[] ) & vice versa in C ?

  • Converting integer to string 

We can convert string to integer very easily in C but to convert integer to string stdlib do not provide any handy function. So we have to do it ourself , It is not that difficult lets write out own functions 'itoa' which will convert integer to C string.


Note: memory allocated to buffer should be released by caller of 'itoa' function.
  • Converting string to integer

It is very simple . We have in built function atoi(const char *) included in stdlib.h which converts string representation in numeric value.



Above snippets converts string "10" to numeric value 10. you can check live example HERE.