Thread: Case statments with long strings... is it possible?

  1. #1

    Case statments with long strings... is it possible?

    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 :-)

  2. #2
    Registered User
    Join Date
    Feb 2002
    How are you doing this? Are you using strcmp() ?

  3. #3
    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 :-)

  4. #4
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    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.

  5. #5
    Join Date
    Aug 2001
    If it's somewhat speed critical use a hash table otherwise the easiest way is to have a bunch of if statements.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 03-05-2009, 11:32 AM
  2. Open file name object
    By JJFMJR in forum Windows Programming
    Replies: 3
    Last Post: 09-14-2007, 05:44 PM
  3. ascii rpg help
    By aaron11193 in forum C Programming
    Replies: 18
    Last Post: 10-29-2006, 01:45 AM
  4. Replies: 27
    Last Post: 10-11-2006, 04:27 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM