current = current * 10 + (c - '0');

后端 未结 4 1644
鱼传尺愫
鱼传尺愫 2021-01-21 11:58

I\'m trying to read unknown number of integers by this piece of code:

while (1) {
        int c = getchar ();
        if (c == EOF)
            break;
        el         


        
4条回答
  •  攒了一身酷
    2021-01-21 12:49

    The digits are represented in ASCII by increasing values: 0 is 48, 1 is 49, and so on. Since characters in C are just integers in disguise, you can subtract the ASCII value of 0 from any other digit to obtain the numerical value of the digit. For example, '1' - '0' is the same as 49 - 48 which is 1.

提交回复
热议问题