今日はC言語でテストしていて、2つの小さなcファイルを作成しました
main.c
#include<conio.h>
void testing();
int main()
{
testing();
getch();
return 0;
}
testing.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');
}
私が直面している問題は、ユーザーから1文字を読み取ってから2回ループし、理由がわからないことです
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 でコンパイルしました。