Well I am new to programming. I have problem with my code. In first run it works fine, but in second run it skips scanf and comes out of loop while debugger shows ch is still y and one more thing debugger shows is that in second iteration it does not reach to scanf. And even if the scanf gets skipped, why does control comes out of loop as value of ch has not changed. Kindly help me out.
#include<stdio.h>
int main()
{
char ch=y;
while(ch==y || ch==Y)
{
printf("Its hello again to check\n");
printf("Do you wish to continue: y or n\n");
scanf("%c", &ch);
}
exit(0);
}
And if I modify this code again like below #include
int main()
{
char ch=y;
while(ch==y || ch==Y)
{
printf("Its hello again to check\n");
printf("Do you wish to continue: y or n\n");
scanf("%c", &ch);
//fflush(stdin);
printf("Choice entered %d \n", ch);
}
exit(0);
}
It then last printf gets skipped even if I use fflush.