{"id":177132,"date":"2020-04-25T09:34:30","date_gmt":"2020-04-25T01:34:30","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=177132"},"modified":"2020-04-20T09:36:05","modified_gmt":"2020-04-20T01:36:05","slug":"introduction-to-the-2","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/introduction-to-the-2.html","title":{"rendered":"C \u8bed\u8a00\u6574\u6570\u4e0e\u5b57\u7b26\u4e32\u7684\u76f8\u4e92\u8f6c\u6362\u4ecb\u7ecd"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nC \u8bed\u8a00\u4e2d\u6574\u6570\u4e0e\u5b57\u7b26\u4e32\u7684\u76f8\u4e92\u8f6c\u6362\uff0c\u6709\u5e7f\u6cdb\u5e94\u7528\u7684\u62d3\u5c55\u51fd\u6570(\u975e\u6807\u51c6\u5e93)\uff0c\u4e5f\u53ef\u4ee5\u81ea\u5df1\u5c1d\u8bd5\u7b80\u5355\u7684\u5b9e\u73b0\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u4e00\u3001\u7b80\u8ff0<\/strong><\/div>\n

C \u8bed\u8a00\u4e2d\u6574\u6570\u4e0e\u5b57\u7b26\u4e32\u7684\u76f8\u4e92\u8f6c\u6362\uff0c\u6709\u5e7f\u6cdb\u5e94\u7528\u7684\u62d3\u5c55\u51fd\u6570(\u975e\u6807\u51c6\u5e93)\uff0c\u4e5f\u53ef\u4ee5\u81ea\u5df1\u5c1d\u8bd5\u7b80\u5355\u7684\u5b9e\u73b0\u3002<\/p>\n

\u4e8c\u3001\u6574\u6570\u8f6c\u5b57\u7b26\u4e32<\/strong><\/div>\n
1\u3001\u62d3\u5c55\u51fd\u6570 itoa<\/strong><\/span><\/div>\n

itoa (\u8868\u793a integer to alphanumeric)\u662f\u628a\u6574\u578b\u6570\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\u7684\u4e00\u4e2a\u51fd\u6570\u3002<\/p>\n

windows \u73af\u5883\u4e0b\uff0c\u5728 \u5934\u6587\u4ef6\u4e2d\u6709:<\/p>\n

char* 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>\n

char* 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>\/\/\u51fd\u6570\u58f0\u660e <\/span><\/span>\r\n<\/span>int<\/span> <\/span>main<\/span>(<\/span>)<\/span>\r\n<\/span>{<\/span>\r\n <\/span>int<\/span> <\/span>number1<\/span> = <\/span>123456<\/span>;\r\n <\/span>int<\/span> <\/span>number2<\/span> = -<\/span>123456<\/span>;\r\n <\/span>char<\/span> <\/span>string<\/span>[<\/span>16<\/span>]<\/span> = <\/span>{<\/span>0<\/span>}<\/span>;\r\n <\/span>Int2String<\/span>(<\/span>number1<\/span>,<\/span>string<\/span>)<\/span>;\r\n <\/span>printf<\/span>(<\/span>\"<\/span>\u6570\u5b57\uff1a%d \u8f6c\u6362\u540e\u7684\u5b57\u7b26\u4e32\u4e3a\uff1a%s<\/span>\\<\/span>n<\/span>\"<\/span>,<\/span>number1<\/span>,<\/span>string<\/span>)<\/span>;\r\n <\/span>Int2String<\/span>(<\/span>number2<\/span>,<\/span>string<\/span>)<\/span>;\r\n <\/span>printf<\/span>(<\/span>\"<\/span>\u6570\u5b57\uff1a%d \u8f6c\u6362\u540e\u7684\u5b57\u7b26\u4e32\u4e3a\uff1a%s<\/span>\\<\/span>n<\/span>\"<\/span>,<\/span>number2<\/span>,<\/span>string<\/span>)<\/span>;\r\n <\/span>return<\/span> <\/span>0<\/span>;\r\n<\/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>\/\/10\u8fdb\u5236 <\/span><\/span>\r\n<\/span>{<\/span>\r\n <\/span>int<\/span> <\/span>i<\/span> = <\/span>0<\/span>;<\/span>\/\/\u6307\u793a\u586b\u5145str <\/span><\/span>\r\n <\/span>if<\/span>(<\/span>num<\/span><<\/span>0<\/span>)<\/span>\/\/\u5982\u679cnum\u4e3a\u8d1f\u6570\uff0c\u5c06num\u53d8\u6b63 <\/span><\/span>\r\n <\/span>{<\/span>\r\n <\/span>num<\/span> = -<\/span>num<\/span>;\r\n <\/span>str<\/span>[<\/span>i<\/span>++<\/span>]<\/span> = '-';\r\n <\/span>}<\/span> \r\n <\/span>\/\/\u8f6c\u6362 <\/span><\/span>\r\n <\/span>do<\/span>\r\n <\/span>{<\/span>\r\n <\/span>str<\/span>[<\/span>i<\/span>++<\/span>]<\/span> = <\/span>num<\/span>%<\/span>10<\/span>+<\/span>48<\/span>;<\/span>\/\/\u53d6num\u6700\u4f4e\u4f4d \u5b57\u7b260~9\u7684ASCII\u7801\u662f48~57\uff1b\u7b80\u5355\u6765\u8bf4\u6570\u5b570+48=48\uff0cASCII\u7801\u5bf9\u5e94\u5b57\u7b26'0' <\/span><\/span>\r\n <\/span>num<\/span> \/= <\/span>10<\/span>;<\/span>\/\/\u53bb\u6389\u6700\u4f4e\u4f4d <\/span><\/span>\r\n <\/span>}<\/span>while<\/span>(<\/span>num<\/span>)<\/span>;<\/span>\/\/num\u4e0d\u4e3a0\u7ee7\u7eed\u5faa\u73af<\/span><\/span>\r\n \r\n <\/span>str<\/span>[<\/span>i<\/span>]<\/span> = '\\<\/span>0<\/span>';\r\n \r\n <\/span>\/\/\u786e\u5b9a\u5f00\u59cb\u8c03\u6574\u7684\u4f4d\u7f6e <\/span><\/span>\r\n <\/span>int<\/span> <\/span>j<\/span> = <\/span>0<\/span>;\r\n <\/span>if<\/span>(<\/span>str<\/span>[<\/span>0<\/span>]<\/span>=='-'<\/span>)<\/span>\/\/\u5982\u679c\u6709\u8d1f\u53f7\uff0c\u8d1f\u53f7\u4e0d\u7528\u8c03\u6574 <\/span><\/span>\r\n <\/span>{<\/span>\r\n <\/span>j<\/span> = <\/span>1<\/span>;<\/span>\/\/\u4ece\u7b2c\u4e8c\u4f4d\u5f00\u59cb\u8c03\u6574 <\/span><\/span>\r\n ++<\/span>i<\/span>;<\/span>\/\/\u7531\u4e8e\u6709\u8d1f\u53f7\uff0c\u6240\u4ee5\u4ea4\u6362\u7684\u5bf9\u79f0\u8f74\u4e5f\u8981\u540e\u79fb1\u4f4d <\/span><\/span>\r\n <\/span>}<\/span>\r\n <\/span>\/\/\u5bf9\u79f0\u4ea4\u6362 <\/span><\/span>\r\n <\/span>for<\/span>(<\/span>;<\/span>j<\/span><<\/span>i<\/span>\/<\/span>2<\/span>;<\/span>j<\/span>++<\/span>)<\/span>\r\n <\/span>{<\/span>\r\n <\/span>\/\/\u5bf9\u79f0\u4ea4\u6362\u4e24\u7aef\u7684\u503c \u5176\u5b9e\u5c31\u662f\u7701\u4e0b\u4e2d\u95f4\u53d8\u91cf\u4ea4\u6362a+b\u7684\u503c\uff1aa=a+b;b=a-b;a=a-b; <\/span><\/span>\r\n <\/span>str<\/span>[<\/span>j<\/span>]<\/span> = <\/span>str<\/span>[<\/span>j<\/span>]<\/span> + <\/span>str<\/span>[<\/span>i<\/span>-<\/span>1<\/span>-<\/span>j<\/span>]<\/span>;\r\n <\/span>str<\/span>[<\/span>i<\/span>-<\/span>1<\/span>-<\/span>j<\/span>]<\/span> = <\/span>str<\/span>[<\/span>j<\/span>]<\/span> - <\/span>str<\/span>[<\/span>i<\/span>-<\/span>1<\/span>-<\/span>j<\/span>]<\/span>;\r\n <\/span>str<\/span>[<\/span>j<\/span>]<\/span> = <\/span>str<\/span>[<\/span>j<\/span>]<\/span> - <\/span>str<\/span>[<\/span>i<\/span>-<\/span>1<\/span>-<\/span>j<\/span>]<\/span>;\r\n <\/span>}<\/span> \r\n \r\n <\/span>return<\/span> <\/span>str<\/span>;<\/span>\/\/\u8fd4\u56de\u8f6c\u6362\u540e\u7684\u503c <\/span><\/span>\r\n<\/span>}<\/span><\/div><\/pre>\n

\u6548\u679c\u622a\u56fe:
\n\"\"<\/p>\n

\u4e09\u3001\u5b57\u7b26\u4e32\u8f6c\u6574\u6570<\/strong><\/div>\n
1\u3001\u62d3\u5c55\u51fd\u6570<\/strong><\/span><\/div>\n

atoi (\u8868\u793a alphanumeric to integer)\u662f\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6574\u578b\u6570\u7684\u4e00\u4e2a\u51fd\u6570\u3002<\/p>\n

windows \u73af\u5883\u4e0b\uff0c\u5728 \u5934\u6587\u4ef6\u4e2d\u3002<\/p>\n

int atoi(const char *nptr);\/\/\u5b57\u7b26\u4e32\u8f6c\u6574\u6570\u51fd\u6570\uff0cnptr: \u8981\u8f6c\u6362\u7684\u5b57\u7b26\u4e32<\/p>\n

\u51fd\u6570\u6e90\u7801<\/strong><\/p>\n

int  atoi(const char *nptr)\r\n{\r\n        return (int)atol(nptr);\r\n}\r\n \r\nlong  atol(const char *nptr)\r\n{\r\n        int c;              \/* \u5f53\u524d\u8981\u8f6c\u6362\u7684\u5b57\u7b26(\u4e00\u4e2a\u4e00\u4e2a\u5b57\u7b26\u8f6c\u6362\u6210\u6570\u5b57) *\/\r\n        long total;         \/* \u5f53\u524d\u8f6c\u6362\u7ed3\u679c *\/\r\n        int sign;           \/* \u6807\u5fd7\u8f6c\u6362\u7ed3\u679c\u662f\u5426\u5e26\u8d1f\u53f7*\/\r\n \r\n        \/*\u8df3\u8fc7\u7a7a\u683c\uff0c\u7a7a\u683c\u4e0d\u8fdb\u884c\u8f6c\u6362*\/\r\n        while ( isspace((int)(unsigned char)*nptr) )\r\n            ++nptr;\r\n \r\n        c = (int)(unsigned char)*nptr++;\/\/\u83b7\u53d6\u4e00\u4e2a\u5b57\u7b26\u51c6\u5907\u8f6c\u6362 \r\n        sign = c;           \/*\u4fdd\u5b58\u7b26\u53f7\u6807\u793a*\/\r\n        if (c == '-' || c == '+')\r\n            c = (int)(unsigned char)*nptr++;    \/*\u8df3\u8fc7'+'\u3001'-'\u53f7\uff0c\u4e0d\u8fdb\u884c\u8f6c\u6362*\/\r\n \r\n        total = 0;\/\/\u8bbe\u7f6e\u8f6c\u6362\u7ed3\u679c\u4e3a0 \r\n \r\n        while (isdigit(c)) {\/\/\u5982\u679c\u5b57\u7b26\u662f\u6570\u5b57 \r\n            total = 10 * total + (c - '0');     \/* \u6839\u636eASCII\u7801\u5c06\u5b57\u7b26\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684\u6570\u5b57\uff0c\u5e76\u4e14\u4e5810\u7d2f\u79ef\u5230\u7ed3\u679c *\/\r\n            c = (int)(unsigned char)*nptr++;    \/* \u53d6\u4e0b\u4e00\u4e2a\u5b57\u7b26 *\/\r\n        }\r\n \r\n         \/\/\u6839\u636e\u7b26\u53f7\u6307\u793a\u8fd4\u56de\u662f\u5426\u5e26\u8d1f\u53f7\u7684\u7ed3\u679c \r\n        if (sign == '-')\r\n            return -total;\r\n        else\r\n            return total;  \r\n}<\/pre>\n

\u793a\u4f8b\u7a0b\u5e8f\uff1a<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

#include\r\n#include \r\n \r\nint main()\r\n{\r\n    printf(\"\u5b57\u7b26\u4e32\\\"123456\\\"\u8f6c\u6362\u4e3a\u6570\u5b57\uff1a%d\\n\",atoi(\"123456\"));\r\n    printf(\"\u5b57\u7b26\u4e32\\\"-123456\\\"\u8f6c\u6362\u4e3a\u6570\u5b57\uff1a%d\\n\",atoi(\"-123456\"));\r\n    return 0;\r\n \r\n}<\/pre>\n

\"\"<\/p>\n

2\u3001\u81ea\u5df1\u7b80\u5355\u5b9e\u73b0<\/strong><\/span><\/div>\n

\u5b9e\u73b0\u6e90\u7801:<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

#include\r\n \r\nint String2Int(char *str);\/\/\u51fd\u6570\u58f0\u660e \r\nint main()\r\n{\r\n    printf(\"\u5b57\u7b26\u4e32\\\"123456\\\"\u8f6c\u6362\u4e3a\u6570\u5b57\uff1a%d\\n\",String2Int(\"123456\"));\r\n    printf(\"\u5b57\u7b26\u4e32\\\"-123456\\\"\u8f6c\u6362\u4e3a\u6570\u5b57\uff1a%d\\n\",String2Int(\"-123456\"));\r\n    return 0;\r\n}\r\n \r\nint String2Int(char *str)\/\/\u5b57\u7b26\u4e32\u8f6c\u6570\u5b57 \r\n{\r\n    char flag = '+';\/\/\u6307\u793a\u7ed3\u679c\u662f\u5426\u5e26\u7b26\u53f7 \r\n    long res = 0;\r\n    \r\n    if(*str=='-')\/\/\u5b57\u7b26\u4e32\u5e26\u8d1f\u53f7 \r\n    {\r\n        ++str;\/\/\u6307\u5411\u4e0b\u4e00\u4e2a\u5b57\u7b26 \r\n        flag = '-';\/\/\u5c06\u6807\u5fd7\u8bbe\u4e3a\u8d1f\u53f7 \r\n    } \r\n    \/\/\u9010\u4e2a\u5b57\u7b26\u8f6c\u6362\uff0c\u5e76\u7d2f\u52a0\u5230\u7ed3\u679cres \r\n    while(*str>=48 && *str<57)\/\/\u5982\u679c\u662f\u6570\u5b57\u624d\u8fdb\u884c\u8f6c\u6362\uff0c\u6570\u5b570~9\u7684ASCII\u7801\uff1a48~57 \r\n    {\r\n        res = 10*res+  *str++-48;\/\/\u5b57\u7b26'0'\u7684ASCII\u7801\u4e3a48,48-48=0\u521a\u597d\u8f6c\u5316\u4e3a\u6570\u5b570 \r\n    } \r\n \r\n    if(flag == '-')\/\/\u5904\u7406\u662f\u8d1f\u6570\u7684\u60c5\u51b5\r\n    {\r\n        res = -res;\r\n    }\r\n \r\n    return (int)res;\r\n}<\/pre>\n

\u622a\u56fe:
\n\"\"<\/p>\n

\u56db\u3001\u5229\u7528 sprintf() \u51fd\u6570\u548c sscanf() \u51fd\u6570<\/strong><\/div>\n
\u6574\u6570\u8f6c\u5b57\u7b26\u4e32<\/strong><\/span><\/div>\n

\u6d4b\u8bd5\u4ee3\u7801\uff1a<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

#include \r\n \r\nchar* Int2String(int num,char *str);\/\/\u51fd\u6570\u58f0\u660e \r\nint main()\r\n{\r\n    int number1 = 123456;\r\n    int number2 = -123456;\r\n    char string[16] = {0};\r\n    Int2String(number1,string);\r\n    printf(\"\u6570\u5b57\uff1a%d \u8f6c\u6362\u540e\u7684\u5b57\u7b26\u4e32\u4e3a\uff1a%s\\n\",number1,string);\r\n    Int2String(number2,string);\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}\r\n \r\nchar* Int2String(int num,char *str)\r\n{\r\n    sprintf(str, \"%d\", num);\r\n \r\n    return str;\r\n \r\n}<\/pre>\n

\u8fd0\u884c\u7ed3\u679c\uff1a
\n\"\"<\/p>\n

\u5b57\u7b26\u4e32\u8f6c\u6574\u6570<\/strong><\/span><\/div>\n

\u6d4b\u8bd5\u4ee3\u7801\uff1a<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

#include\r\n \r\nint String2Int(char *str);\/\/\u51fd\u6570\u58f0\u660e \r\nint main()\r\n{\r\n    printf(\"\u5b57\u7b26\u4e32\\\"123456\\\"\u8f6c\u6362\u4e3a\u6570\u5b57\uff1a%d\\n\",String2Int(\"123456\"));\r\n    printf(\"\u5b57\u7b26\u4e32\\\"-123456\\\"\u8f6c\u6362\u4e3a\u6570\u5b57\uff1a%d\\n\",String2Int(\"-123456\"));\r\n    return 0;\r\n}\r\n \r\nint String2Int(char *str)\/\/\u5b57\u7b26\u4e32\u8f6c\u6570\u5b57 \r\n{\r\n    char flag = '+';\/\/\u6307\u793a\u7ed3\u679c\u662f\u5426\u5e26\u7b26\u53f7 \r\n    long res = 0;\r\n    \r\n    if(*str=='-')\/\/\u5b57\u7b26\u4e32\u5e26\u8d1f\u53f7 \r\n    {\r\n        ++str;\/\/\u6307\u5411\u4e0b\u4e00\u4e2a\u5b57\u7b26 \r\n        flag = '-';\/\/\u5c06\u6807\u5fd7\u8bbe\u4e3a\u8d1f\u53f7 \r\n    } \r\n    \r\n    sscanf(str, \"%ld\", &res);\r\n    if(flag == '-')\r\n    {\r\n        res = -res;\r\n    }\r\n    return (int)res;\r\n}<\/pre>\n

\u8fd0\u884c\u7ed3\u679c\uff1a
\n\"\"<\/p>\n

\u4e94\u3001\u9644ASCII\u7801\u8868(\u90e8\u5206)<\/strong><\/div>\n

\"\"<\/p>\n","protected":false},"excerpt":{"rendered":"

C \u8bed\u8a00\u4e2d\u6574\u6570\u4e0e\u5b57\u7b26\u4e32\u7684\u76f8\u4e92\u8f6c\u6362\uff0c\u6709\u5e7f\u6cdb\u5e94\u7528\u7684\u62d3\u5c55\u51fd\u6570(\u975e\u6807\u51c6\u5e93)\uff0c\u4e5f\u53ef\u4ee5\u81ea\u5df1\u5c1d\u8bd5\u7b80\u5355\u7684\u5b9e\u73b0\u3002 itoa (\u8868 […]<\/p>\n","protected":false},"author":321,"featured_media":177140,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-177132","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/177132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/321"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=177132"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/177132\/revisions"}],"predecessor-version":[{"id":177143,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/177132\/revisions\/177143"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/177140"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=177132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=177132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=177132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}