switch statement problems

This is a discussion on switch statement problems within the C Programming forums, part of the General Programming Boards category; I have the function: Code: static int check(Node * t){ int flag = FALSE; int flag1 = FALSE; switch(t->type){ case ...

  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 08:42 PM.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    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?
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  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,185
    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,185
    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,058
    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, 07:32 PM
  2. Stack operations from switch statement elements
    By mlsrar in forum C Programming
    Replies: 15
    Last Post: 10-02-2008, 02:12 PM
  3. switch statement
    By guillermoh in forum C Programming
    Replies: 5
    Last Post: 03-10-2008, 03: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, 05:16 PM

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