#include <stdio.h>
#include <stdlib.h>
void main ()
{
char c;
int choice, dummy;
do {
printf ("\n1. Print Hello\n2. Print Javatpoint\n3. Exit\n");
scanf ("%d", &choice);
switch (choice)
{
case 1:
printf ("Hello");
break;
case 2:
printf ("Javatpoint");
break;
case 3:
exit (0);
break;
default:
printf ("please enter valid choice");
}
printf ("\ndo you want to enter more?");
scanf ("%d", &dummy);
scanf ("%c", &c);
} while (c == 'y');
}
After printf function (do you want to enter more ?) there are 2 more scanf
functions. One is taking integer which is stored in dummy and other taking a character.
So when I enter character 'y'
, the program runs well.
But when I enter any integer, the program instant terminates itself. But why? Hasn't it left to take a character by another scanf function ?
In short there are two scanf
functions, but I can enter 1
. why ?