nested switch issue

This is a discussion on nested switch issue within the C Programming forums, part of the General Programming Boards category; Code: switch(operation) { case 'R': if(!strcmp(opcode, "add")) { machineLine[7] = '0'; machineLine[8] = '0'; machineLine[9] = '0'; } /*next 3 ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    5

    nested switch issue

    Code:
    	switch(operation)
    	{
    		case 'R': 
    			if(!strcmp(opcode, "add"))
    			{
    				machineLine[7] = '0';
    				machineLine[8] = '0';
    				machineLine[9] = '0';
    			}
    			/*next 3 switch statements set bits associated with register values*/
    			switch(arg0)
    			{
    				case '0':
    					machineLine[10] = '0';
    					machineLine[11] = '0';
    					machineLine[12] = '0';
    					break;
    				case '1':
    					machineLine[10] = '0';
    					machineLine[11] = '0';
    					machineLine[12] = '1';
    					break;
    				case '2':
    					machineLine[10] = '0';
    					machineLine[11] = '1';
    					machineLine[12] = '0';
    					break;
    				case '3':
    					machineLine[10] = '0';
    					machineLine[11] = '1';
    					machineLine[12] = '1';
    					break;
    			}
    			break;
    	}
    the problem is, every compiler i have used (g++, gcc, MS visual) gives me an error like this : "error: switch quantity not an integer"
    I need to reading in a string on the nested switch statement, but the compilers arent letting me put anything except an integer in there?? why is this??
    note: variable "operation" is a char
    arg0 is a string;
    machineLine is an array
    the switch(arg0) is giving the error. does anyone have any code examples using a nested switch? it definitly should not be restricting any parameter of a nested switch to only integers.
    Last edited by fsu_altek; 02-15-2006 at 08:57 PM.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Including the data types of the associated variables is often the key to figuring out what is wrong.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Not sure if this was part of the edit...
    arg0 is a string;
    ...but it's likely what is wrong. A pointer is not an integer. Being a "string", you the expression arg0 resolves into a pointer to the first element of the string. Did you mean *arg0?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    5
    well it looks like that solved it! I totally forgot about it being a string, even tho arg0 is just a srting with 1 element in it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Case Switch issue
    By pc_doctor in forum C Programming
    Replies: 8
    Last Post: 12-06-2008, 05:24 AM
  2. A nested if inside the switch
    By Extropian in forum C Programming
    Replies: 20
    Last Post: 08-15-2005, 01:23 AM
  3. nested switch
    By kurz7 in forum C Programming
    Replies: 1
    Last Post: 09-07-2003, 09:32 AM
  4. Help with Nested Switch
    By liquidspaces in forum C++ Programming
    Replies: 9
    Last Post: 03-28-2003, 03:08 PM
  5. nested switch
    By ccmac in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2002, 08:19 PM

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