By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

why does this prg does not display "NONE"

P: n/a
int a=10;
switch(a)
{
case '1':
printf("ONE\n");
break;
case '2':
printf("TWO\n");
break;
defa1ut:
printf("NONE\n");
}

Sep 20 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
sunny said:
int a=10;
switch(a)
{
case '1':
printf("ONE\n");
break;
case '2':
printf("TWO\n");
break;
defa1ut:
Well, duh.
printf("NONE\n");
}
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 20 '06 #2

P: n/a
sunny wrote:
int a=10;
switch(a)
{
case '1':
printf("ONE\n");
break;
case '2':
printf("TWO\n");
break;
defa1ut:
printf("NONE\n");
}
propably because a does not have value defalut :-)
../Preben
Sep 20 '06 #3

P: n/a
check the spelling of default ... and dont waste others time with such
hopeless questions
Preben Traerup wrote:
sunny wrote:
int a=10;
switch(a)
{
case '1':
printf("ONE\n");
break;
case '2':
printf("TWO\n");
break;
defa1ut:
printf("NONE\n");
}
propably because a does not have value defalut :-)
./Preben
Sep 20 '06 #4

P: n/a

sunny a écrit :
int a=10;
switch(a)
{
case '1':
printf("ONE\n");
break;
case '2':
printf("TWO\n");
break;
default:
printf("NONE\n");
}
Because it seems that with the quotes, you're evalutating the character
(ascii code), not the value itself.
Try :
switch(a)
{
case 1 :
Sep 20 '06 #5

P: n/a
sunny wrote:
int a=10;
switch(a)
{
case '1':
printf("ONE\n");
break;
case '2':
printf("TWO\n");
break;
defa1ut:
printf("NONE\n");
}
Why do people continue to post this lame snippet?
Sep 20 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.