关于输入缓冲中'\n'字符的疑问
程序如下:
#include<stdio.h>
int main(){
char ch;
int a,b,c;
c=5;
printf("Enter first number:");
while(scanf("%d",&a)!=1){
while((ch=getchar())!='\n')putchar(ch);
printf(" is not a number .\nplease enter a number such as 2.5,-22 or 3:");
}
printf("Enter second number:");
while(scanf("%d",&b)!=1){
while((ch=getchar())!='\n')putchar(ch);
printf(" is not a number .\nplease enter a number such as 2.5,-22 or 3:");
}
c=getchar();
printf("%d %d %d\n\n \a",a,b,c);
return 0;
}
第一个疑问:在此程序中,若不输入任何字符,只是按空白键(键Enter tab back),程序是不执行,还是在循环执行、判断呢?
第二个疑问:第一次的scanf()输入数字后的空格并没有被第二次的scanf()赋值到b中,这是为何?
第三个疑问:显然输出c的值不是初赋值时的5,在我机上输出是10,这是因为getchar()将\n值赋值给c, 但ASC码值为10的是DLE,怎会有相关呢?
第四个疑问:这其中内存的缓冲区有更新吗?还是一直地往后储存输入?
能详细解说一下此程序中缓冲与赋值的状态与过程吗?