今天在用c语言测试,做了两个小c文件
主程序
#include<conio.h>
void testing();
int main()
{
testing();
getch();
return 0;
}
测试.c
#include <stdio.h>
void testing()
{
char ch;
printf("Hello Testing\n");
do{
printf("Enter Character : ");
ch=getchar();
printf("You Entered : %c\n",ch);
testing();
}while(ch!='N');
}
我面临的问题是它从用户那里读取一个字符,然后循环两次,我不知道为什么
output
Hello Testing
Enter Character : k //(i entered k)
You Entered : k
Hello Testing// why this is displayed twice??
Enter Character : You Entered :// i don't press any key and it moves to next iteration
Hello Testing
Enter Character : // here i can enter character again and it happens again twice
我已经在 Visual Studio 2012 上编译了它。