执行以下代码时遇到困难。完成一次执行后,变量't'取空值。该问题已通过使用getch()而不是scanf()来解决。但我不知道为什么会发生。任何解释? 这是没有用的程序。getch()和scanf()函数之间的区别
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
char t;
void main()
{
while(1)
{
scanf("%c",&t);
printf("\nValue of t = %c",t);
printf("\nContinue (Y/N):");
char a=getche();
if(a=='n' || a=='N')
exit(0);
}
}
现在,这是正确执行的程序。
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
char t;
void main()
{
while(1)
{
t=getch();
printf("\nValue of t = %c",t);
printf("\nContinue (Y/N):");
char a=getche();
if(a=='n' || a=='N')
exit(0);
}
}
[奇怪的循环可能重复使用%c](http://stackoverflow.com/questions/13814128/odd-loop-does-not-work-using-c) – 2013-02-18 19:03:40
'void main()'不是托管实现的合法*签名*(除非它们具有扩展名) – pmg 2013-02-18 19:30:12