The output of following code in C is "bad" but problem is that during execution,it only asks for the values of a &b.It doesnt ask for the value of x whose datatype is char.Why So? The Same program if executed in C++ using cout and cin works fine n even asks for the value of x.Why So that the above code works for C++ and not in C?
pls help me...
msi_333
Question subject: Re: code problem
Posted: Mon Oct 11, 2010 10:33 pm
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2272 Location: Earth Has thanked: 39 time Have thanks: 61 time
Code:
scanf("%c",&c);
is think it should be
Code:
scanf("%c",&x);
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
Shikshakanwar
Question subject: Re: code problem
Posted: Wed Oct 13, 2010 12:53 pm
Joined: Wed Oct 13, 2010 12:36 pm Posts: 1 Has thanked: 0 time Have thanks: 1 time
use \n before
use \n before %c in scanf statement as shown below...... main() { int a,b; scanf("%d%d",&a,&b); char x; scanf("\n%c",&c); switch(x); { case'A': printf("good"); break: default: printf("bad"); }