-5

How do you convert an int to a string without using library functions in C?

user2997154
  • 415
  • 7
  • 18

1 Answers1

3

You can achieve this by extracting each bits one by one, like this

str[i] = (char)( (num % 10) - 48 )

48 has to be subtracted because an integer value changing to character goes through an ASCII conversion. Keeping the above line in a loop, that would run for each digit in the number, should do the trick..

Haris
  • 12,120
  • 6
  • 43
  • 70