\u5934\u6587\u4ef6\u4e2d\u6709:<\/p>\nchar* itoa(int value,char*string,int radix);\/\/value: \u8981\u8f6c\u6362\u7684\u6574\u6570\uff0cstring: \u8f6c\u6362\u540e\u7684\u5b57\u7b26\u4e32,radix: \u8f6c\u6362\u8fdb\u5236\u6570\uff0c\u59822,8,10,16 \u8fdb\u5236\u7b49\u3002<\/pre>\n\u51fd\u6570\u6e90\u7801\uff1a<\/strong><\/p>\nchar* itoa(int num,char* str,int radix)\r\n{\r\n char index[]=\"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\/\/\u7d22\u5f15\u8868\r\n unsigned unum;\/\/\u5b58\u653e\u8981\u8f6c\u6362\u7684\u6574\u6570\u7684\u7edd\u5bf9\u503c,\u8f6c\u6362\u7684\u6574\u6570\u53ef\u80fd\u662f\u8d1f\u6570\r\n int i=0,j,k;\/\/i\u7528\u6765\u6307\u793a\u8bbe\u7f6e\u5b57\u7b26\u4e32\u76f8\u5e94\u4f4d\uff0c\u8f6c\u6362\u4e4b\u540ei\u5176\u5b9e\u5c31\u662f\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\uff1b\u8f6c\u6362\u540e\u987a\u5e8f\u662f\u9006\u5e8f\u7684\uff0c\u6709\u6b63\u8d1f\u7684\u60c5\u51b5\uff0ck\u7528\u6765\u6307\u793a\u8c03\u6574\u987a\u5e8f\u7684\u5f00\u59cb\u4f4d\u7f6e;j\u7528\u6765\u6307\u793a\u8c03\u6574\u987a\u5e8f\u65f6\u7684\u4ea4\u6362\u3002\r\n \r\n \/\/\u83b7\u53d6\u8981\u8f6c\u6362\u7684\u6574\u6570\u7684\u7edd\u5bf9\u503c\r\n if(radix==10&&num<0)\/\/\u8981\u8f6c\u6362\u6210\u5341\u8fdb\u5236\u6570\u5e76\u4e14\u662f\u8d1f\u6570\r\n {\r\n unum=(unsigned)-num;\/\/\u5c06num\u7684\u7edd\u5bf9\u503c\u8d4b\u7ed9unum\r\n str[i++]='-';\/\/\u5728\u5b57\u7b26\u4e32\u6700\u524d\u9762\u8bbe\u7f6e\u4e3a'-'\u53f7\uff0c\u5e76\u4e14\u7d22\u5f15\u52a01\r\n }\r\n else unum=(unsigned)num;\/\/\u82e5\u662fnum\u4e3a\u6b63\uff0c\u76f4\u63a5\u8d4b\u503c\u7ed9unum\r\n \r\n \/\/\u8f6c\u6362\u90e8\u5206\uff0c\u6ce8\u610f\u8f6c\u6362\u540e\u662f\u9006\u5e8f\u7684\r\n do\r\n {\r\n str[i++]=index[unum%(unsigned)radix];\/\/\u53d6unum\u7684\u6700\u540e\u4e00\u4f4d\uff0c\u5e76\u8bbe\u7f6e\u4e3astr\u5bf9\u5e94\u4f4d\uff0c\u6307\u793a\u7d22\u5f15\u52a01\r\n unum\/=radix;\/\/unum\u53bb\u6389\u6700\u540e\u4e00\u4f4d\r\n \r\n }while(unum);\/\/\u76f4\u81f3unum\u4e3a0\u9000\u51fa\u5faa\u73af\r\n \r\n str[i]='\\0';\/\/\u5728\u5b57\u7b26\u4e32\u6700\u540e\u6dfb\u52a0'\\0'\u5b57\u7b26\uff0cc\u8bed\u8a00\u5b57\u7b26\u4e32\u4ee5'\\0'\u7ed3\u675f\u3002\r\n \r\n \/\/\u5c06\u987a\u5e8f\u8c03\u6574\u8fc7\u6765\r\n if(str[0]=='-') k=1;\/\/\u5982\u679c\u662f\u8d1f\u6570\uff0c\u7b26\u53f7\u4e0d\u7528\u8c03\u6574\uff0c\u4ece\u7b26\u53f7\u540e\u9762\u5f00\u59cb\u8c03\u6574\r\n else k=0;\/\/\u4e0d\u662f\u8d1f\u6570\uff0c\u5168\u90e8\u90fd\u8981\u8c03\u6574\r\n \r\n char temp;\/\/\u4e34\u65f6\u53d8\u91cf\uff0c\u4ea4\u6362\u4e24\u4e2a\u503c\u65f6\u7528\u5230\r\n for(j=k;j<=(i-1)\/2;j++)\/\/\u5934\u5c3e\u4e00\u4e00\u5bf9\u79f0\u4ea4\u6362\uff0ci\u5176\u5b9e\u5c31\u662f\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\uff0c\u7d22\u5f15\u6700\u5927\u503c\u6bd4\u957f\u5ea6\u5c111\r\n {\r\n temp=str[j];\/\/\u5934\u90e8\u8d4b\u503c\u7ed9\u4e34\u65f6\u53d8\u91cf\r\n str[j]=str[i-1+k-j];\/\/\u5c3e\u90e8\u8d4b\u503c\u7ed9\u5934\u90e8\r\n str[i-1+k-j]=temp;\/\/\u5c06\u4e34\u65f6\u53d8\u91cf\u7684\u503c(\u5176\u5b9e\u5c31\u662f\u4e4b\u524d\u7684\u5934\u90e8\u503c)\u8d4b\u7ed9\u5c3e\u90e8\r\n }\r\n \r\n return str;\/\/\u8fd4\u56de\u8f6c\u6362\u540e\u7684\u5b57\u7b26\u4e32\r\n \r\n}<\/pre>\n\u793a\u4f8b\u7a0b\u5e8f\uff1a<\/p>\n
\u5b9e\u4f8b<\/strong><\/p>\n#include \r\n#include \r\nint main()\r\n{\r\n int number1 = 123456;\r\n int number2 = -123456;\r\n char string[16] = {0};\r\n itoa(number1,string,10);\r\n printf(\"\u6570\u5b57\uff1a%d \u8f6c\u6362\u540e\u7684\u5b57\u7b26\u4e32\u4e3a\uff1a%s\\n\",number1,string);\r\n itoa(number2,string,10);\r\n printf(\"\u6570\u5b57\uff1a%d \u8f6c\u6362\u540e\u7684\u5b57\u7b26\u4e32\u4e3a\uff1a%s\\n\",number2,string);\r\n return 0;\r\n}<\/pre>\n\u6548\u679c\u622a\u56fe\uff1a
\n<\/p>\n
2\u3001\u81ea\u5df1\u7b80\u5355\u5b9e\u73b0<\/strong><\/span><\/div>\n\u5b9e\u73b0\u4ee3\u7801:<\/p>\n
\u5b9e\u4f8b<\/strong><\/p>\n#include<\/span> <\/span><<\/span>stdio.h<\/span>><\/span><\/span>\r\n \r\n<\/span>char<\/span>* <\/span>Int2String<\/span>(<\/span>int<\/span> <\/span>num<\/span>,<\/span>char<\/span> *<\/span>str<\/span>)<\/span>;<\/span>