Code:
#include <stdio.h>
int main()
{
int a,b,c;
char i;
printf("Enter Two numbers\n");
scanf("%d%d",&a,&b);
scanf("%c",&i);
printf("a to add\ns to Subtract");
scanf("%c",&i);
switch(i)
{
case 'a':
c = a + b;
printf("%d",c);
break;
case 's':
c = a-b;
printf("%d",c);
break;
default:
break;
}
return 0;
}
in the above program to get the char i scanf is used two times. If using it for a single time the control jumps to the switch case after getting the integers a and b.
Please explain the flow why this is happening.
also explain the proper usage of scanf..
Thanks and regards,
Iyan