Get number into a string C without stdio

前端 未结 5 1760
忘掉有多难
忘掉有多难 2021-01-21 10:41

I want to know how to get number to string without standard C or C++ functions, for example:

char str[20];
int num = 1234;
// How to convert that number to strin         


        
5条回答
  •  不知归路
    2021-01-21 11:31

    To get the lowest digit, use num % 10. To convert a digit to a character, add '0'. To remove the lowest digit after you've handled it, divide by 10: num /= 10;. Repeat until done.

提交回复
热议问题