-
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.
-
Including the data types of the associated variables is often the key to figuring out what is wrong.
-
Not sure if this was part of the edit......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?
-
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.