To Whomever Can help Me;
Is it possible to use the Switch structure for characters? For example:
switch(char)
{
case 1:char = 'b'
.
.
.
I'm trying to do it, but having trouble. Is this even possible? Any help would be great! Thanks!
Dave
This is a discussion on Using the Switch statement with Characters? within the C Programming forums, part of the General Programming Boards category; To Whomever Can help Me; Is it possible to use the Switch structure for characters? For example: switch(char) { case ...
To Whomever Can help Me;
Is it possible to use the Switch structure for characters? For example:
switch(char)
{
case 1:char = 'b'
.
.
.
I'm trying to do it, but having trouble. Is this even possible? Any help would be great! Thanks!
Dave
It is possible:
try thatCode:char choice; printf("Enter a letter...:"); scanf("%c", choice); switch (choice) { case 'a': { ... } case 'b': { ... } }
Last edited by Lau; 11-18-2002 at 12:14 PM.
Yes, chars and ints can be used in switches. But don't name a variable 'char' it's a keyword y'know? Also, the label cannot be a variable name, see below:
Code:char a = 'a'; char b = 'a'; switch(a){ case b: a = 'x'; break; // <-- illegal. case 't': a = 'z'; break; case 12 : a = 'r'; break; default: a = 'p'; }
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}