Jump to content

what's wrong with this switch statement...

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
13 replies to this topic

#1
digerati

digerati

    Newbie

  • Members
  • Pip
  • 9 posts
Hello Coders,

I am trying to use this switch statement and it gives me an error, saying syntax error before token '=' in all the case statements except for the first and last case statement, all the variables have been defined fine.
switch (op) {
					case 'l': LONG_MODE = TRUE;
						#define LONG_MODE
						break;
					case 'a': DISPLAY_ALL_FILES = TRUE;
						#define DISPLAY_ALL_FILES
						break;
					case 'C': COL_MODE = TRUE; LONG_MODE = FALSE;
						#define COL_MODE
						#undef LONG_MODE
						break;
					case 'd': DIR_MODE = TRUE;
						#define DIR_MODE
						break;
					case 'R': RECURS_MODE = TRUE;
						#define RECURS_MODE
						break;
					case 'S': SORT_MODE = TRUE;
						#define SORT_MODE
						break;
					default : print_help(2);
				}

Thanking you.

Edited by WingedPanther, 30 September 2008 - 08:29 AM.
add code tags


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Without seeing the definitions of your variables, it is very hard to help you out.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
digerati

digerati

    Newbie

  • Members
  • Pip
  • 9 posts
static bool DISPLAY_ALL_FILES = FALSE, DIR_MODE = FALSE, RECURS_MODE = FALSE, LONG_MODE = FALSE, COL_MODE = FALSE, SORT_MODE = FALSE;


These are my variables...

#4
digerati

digerati

    Newbie

  • Members
  • Pip
  • 9 posts
The problem was i was using the same names for both the #define and the variable name, but i am still confused on why it did not complain for the first and last case.

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
not sure.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
LogicKills

LogicKills

    Programmer

  • Members
  • PipPipPipPip
  • 139 posts
Why are you declaring your macros in your switch statements?
http://logickills.org
Science - Math - Hacking - Tech

#7
digerati

digerati

    Newbie

  • Members
  • Pip
  • 9 posts
i have a function which prints depending on the macros defined at that point of time

#8
marwex89

marwex89

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 10,720 posts
Can you achieve this that way?
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#9
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You do realize that ALL the macros end up being defined, don't you? The macros are defined by the preprocesser, not at execution time.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#10
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,709 posts
You'll have to create an int variable and use the bits as flags.

#11
MeTh0Dz

MeTh0Dz

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,119 posts
This code should be completely rewritten.

#12
marwex89

marwex89

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 10,720 posts
I agree.
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa