converting integers to Strings

Source: Internet
Author: User

Because the 64-bit Int_max has a length of not more than 20, the string array is passed into the function.

intNUM2STR (intNumCharstr[]) {    CharC; intI=0, j=0, k=0, TMP = num >0? Num:-1*num; if(num > Int_max | | num < int_min)return-1; if(num<0) {Str[i++] ='-'; ++J; Num*= -1;//The remainder requires attention to be converted to a positive number because -1111%10==-1    }    Else if(0==num) {str[0] ='0'; str[1] =' /';return 0; }     while(TMP) {Str[i]= tmp%Ten+'0'; ++i; TMP/=Ten; } k= i-1;  while(j<k)//String Conversions{C=Str[j]; STR[J]=Str[k]; STR[K]=C; J++; k--; } Str[i]=' /'; return 0;}

The case where integers are positive or negative is considered, but there is a problem, and if the number passed in main is overflow, the numbers in the function are very different.

converting integers to Strings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.