Thread: switch statement problems

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    switch statement problems

    I have the function:

    Code:
    static int check(Node * t){
    int flag = FALSE;
    int flag1 = FALSE;
      
    switch(t->type){
          case A:
            switch(t->kind.a)
            case A1:
            {
            flag = TRUE;
            }
            case A2:
            ...................
            break;
          case B:
           switch(t->kind.b)
           case B1:
            ................
            case B2:
            ..............
            break;
          case C:
           switch(t->kind.c)
           case C1:
           {
           flag1 = TRUE;
           } 
           case C2:
           .......................
           break;
    
         if (flag1 == FALSE && flag == TRUE)
                    fprintf(stderr, "FAILED!\n");
         break;
    
        
    }
    However this doesn't work.. can you tell me why and how to make it work?






    }
    Last edited by -EquinoX-; 10-23-2008 at 07:42 PM.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    The dots:
    Code:
    .....
    won't compile.

    Come on. Describing something as "it won't work" without a full example or error details is a waste of bandwidth.

    Is there a break statement in there anywhere?
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    the ......... represents a bunch of other stuffs, the entire code is 1000 lines and I guess I don't want to copy and paste it all here... This is just the general template of the code

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So what does it do, that you don't want it to do (or vice versa)? And you still might be missing breaks (hard to tell).

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    And for that matter, it will be good practice for you to pare down the program into a small, compilable program that exhibits ... whatever the problem is. (In fact doing so will probably allow you to solve the problem yourself.)

  6. #6
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Are each of the case expressions an integer valued constant ie A A1 A2 B B1 B2 etc.???
    Each case must have a break otherwise execution falls through to the next one and so on and so forth.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting the switch statement to work.
    By mtymightymike in forum C Programming
    Replies: 7
    Last Post: 10-15-2008, 06:32 PM
  2. Stack operations from switch statement elements
    By mlsrar in forum C Programming
    Replies: 15
    Last Post: 10-02-2008, 01:12 PM
  3. switch statement
    By guillermoh in forum C Programming
    Replies: 5
    Last Post: 03-10-2008, 02:17 PM
  4. Switch statement problems
    By ComDriver in forum C++ Programming
    Replies: 5
    Last Post: 02-21-2005, 11:31 AM
  5. Replies: 2
    Last Post: 05-10-2002, 04:16 PM