C 终端输入 字符123 输出 10进制123
#include <stdio.h> #define N 20 int main(int argc, const char *argv[]) { char a[N] = {'\0'}; int i = 0; char ch = '\0'; while((ch=getchar())!='\n') { a[i++] = ch; } int cnt = i; int num = 0; for(i=0;i<cnt;i++) { num = num * 10 + (a[i] - '0'); } //////////////////////////////////// printf("num = %d\n",num); return 0; }