Do switches and arrays mix?

This is a discussion on Do switches and arrays mix? within the C Programming forums, part of the General Programming Boards category; Hi, I need to do something I'm not sure is valid. I want to use a switch statement to check ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    137

    Do switches and arrays mix?

    Hi, I need to do something I'm not sure is valid. I want to use a switch statement to check if an array of three characters is equal to another.
    Eg I have the following possible combinations:
    000
    111
    101
    010
    100
    001
    110
    011

    I want to check an array eg:
    bob[0]=1
    bob[1]=0
    bob[2]=1

    agains't the list to see which it is. Is this possible in a switch statement?

    Thanks
    http://uk.geocities.com/ca_chorltonkids

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Is this possible in a switch statement?
    Yes, but it's ugly and silly and massive and an else if construct works far better.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arrays and Switches
    By CodeGeek20 in forum C Programming
    Replies: 4
    Last Post: 04-22-2008, 08:34 PM
  2. Arrays
    By yoda_21 in forum C Programming
    Replies: 2
    Last Post: 01-27-2002, 12:57 PM

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