Thread: Switch statements for strings

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    9

    Switch statements for strings

    Hi,

    I am trying to use a switch statements for strings but it is not working is there any other method I could use ?? . ( I am trying to avoid using lots of if, else statements )

    Thank you in Advance

    Craig

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Switch statements don't work with strings.

  3. #3
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Thats why he was asking for another method

  4. #4
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Use strcomp() to compare strings.

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    typecast the string to long? this is probably very ugly but could work

  6. #6
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    You would have to iterate through the whole character array and cast it to long, add up the values or something similar and then compare.

    In short, yes, very ugly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using Files Inside Switch Statements
    By arealfind08 in forum C Programming
    Replies: 11
    Last Post: 03-17-2009, 04:49 PM
  2. Switch Statements
    By lazyturtle in forum C++ Programming
    Replies: 12
    Last Post: 05-02-2007, 02:40 AM
  3. Explanation of switch statements
    By ammochck21 in forum C++ Programming
    Replies: 6
    Last Post: 11-04-2006, 02:59 PM
  4. arrays within switch statements
    By divinyl in forum C++ Programming
    Replies: 6
    Last Post: 07-17-2003, 01:56 PM
  5. Switch Statements
    By blackgingr in forum C Programming
    Replies: 3
    Last Post: 10-07-2002, 02:36 PM