Case statments with long strings... is it possible? [Archive] - C Board

PDA

View Full Version : Case statments with long strings... is it possible?


Unregistered
06-21-2002, 11:36 AM
I am currently attemting to make a case statement that switch a char[100] and my compiler doesnt like it... is there another form of a case statment that accepts long strings?

P.S. If there isnt ont tell me becuase i can convert to If statments... but that makes the code look ugly, and ugly is bad :-)

Barjor
06-21-2002, 11:40 AM
How are you doing this? Are you using strcmp() ?

Unregistered
06-21-2002, 11:44 AM
no i am not using strcmp() i am using switch... I am nearly positive this should only be used for integers or single characters, but I wanted my code to look pretty and run smoothly :-)

JoshG
06-21-2002, 11:03 PM
I think a switch statement will only work with constant values, but isn't a string a constant value? Wait, you can not use a non constant variable, so I guess it wouldn't work.

Nick
06-21-2002, 11:22 PM
If it's somewhat speed critical use a hash table otherwise the easiest way is to have a bunch of if statements.