Get number into a string C without stdio

前端 未结 5 1758
忘掉有多难
忘掉有多难 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:23

    Convert it char by char, e.g. the last char of the string is '4', the previous one is '3' and so on. Use math to determine the chars, it might be easier to create "4321" string and then rotate it.

提交回复
热议问题