Mon Oct 11, 2010 6:10 pm
pls can anyone help me ?? i have a problem with the following code...The code is ..
- Code:
main()
{
int a,b;
scanf("%d%d",&a,&b);
char x;
scanf("%c",&c);
switch(x);
{
case'A':
printf("good");
break:
default:
printf("bad");
}
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...
Mon Oct 11, 2010 10:33 pm
- Code:
scanf("%c",&c);
is think it should be
- Code:
scanf("%c",&x);
Wed Oct 13, 2010 12:53 pm
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");
}
Sat Oct 16, 2010 8:28 am
ya thank u but can u pls tell me whats the significance of '\n' here in the program....pls
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.