为什么这个c程序打印两次

时间:2017-11-01 19:56:52

标签: c stdout

#include <stdio.h>

int main()
{
        char c = 'A';
        while (c != ',')
        {
                printf("Input a character:");
                scanf("%c", &c);
                if (c >= '0' && c <= '9')
                {
                        printf("%d\n", (int)c);
                }
        }
}

在接受第一组输入后,此代码打印出&#34;输入一个字符&#34;每次两次 - 这是为什么?

1 个答案:

答案 0 :(得分:1)

因为您按下数字PLUS输入并在下次通话时由#include <stdio.h> int main(void) { char c = 'A'; while (c != ',') { printf("Input a character:"); if (scanf("%c", &c) != 1) { return 0; // we stop if user don't input anything } if (c >= '0' && c <= '9') { printf("%d\n", (int)c); // by the way did you want (int)(c - '0') ? } else { printf("enter a number ! you enter %d\n", c); } } } 读取

Property 'lastModified' does not exist on type 'File'.
相关问题