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

后端 未结 4 1640
鱼传尺愫
鱼传尺愫 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:34

    The character '0' does not have ASCII value 0. However, fortunately the character '1' does have ASCII value '0' + 1, and so forth through 2, 3, 4, 5, 6, 7, 8, and 9. Therefore (pseudo code) 'n' - '0' == n holds for each digit.

提交回复
热议问题