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

This is a discussion on Case statments with long strings... is it possible? within the Game Programming forums, part of the General Programming Boards category; I am currently attemting to make a case statement that switch a char[100] and my compiler doesnt like it... is ...

  1. #1
    Unregistered
    Guest

    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
    Posts
    591
    How are you doing this? Are you using strcmp() ?

  3. #3
    Unregistered
    Guest
    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
    Posts
    326
    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
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    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, 10: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 Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21