I was going through some program when i came across this.
#include<stdio.h>
void main()
{
char z;
do
{
printf("1st line\n");
printf("2nd line\n");
scanf("%c",&z);
switch(z)
{
case 'a':printf("this is case a\n");
break;
case 'b':printf("this is case b\n");
break;
case 'c':printf("Exit\n");
return;
break;
default:
printf("this is default\n");
break;
}
}while(1);
}
1st time i give an input, the output is proper. But after the first input is given and the loop starts for the second time, scanf statement isn't executed at all. The printf statements get executed though and also the default case.
1st line
2nd line
b
this is case b
1st line
2nd line
this is default
1st line
2nd line