unable to understand why ?
#include <stdio.h>
int main()
{
int i;
printf("\n\nEnter 1st value : ");
i=getchar();
printf("\nvalue you've entered is \'%c\'\n\n", i);
printf("Enter 2nd value : ");
i=getchar();
printf("\nvalue you've entered is \'%c\'\n", i);
return 0;
}
the above code will not let me enter by 2nd value. It terminates to the very end 'Hit ENTER to continue'
I put a blank getchar()
just above the second value line ... and viola the code suddenly worked ... it sought inputs for both values
i am puzzled ...
if not for, accidentally introducing the blank getchar()
i was lost trying to figure out what was wrong in the above code ...
this code works, but no idea why the empty getchar()
line was required ???
#include <stdio.h>
int main()
{
int i;
printf("\n\nEnter 1st value : ");
i=getchar();
printf("\nvalue you've entered is \'%c\'\n\n", i);
getchar(); // why is it necessary to add this line ???
printf("Enter 2nd value : ");
i=getchar();
printf("\nvalue you've entered is \'%c\'\n", i);
return 0;
}