I'm reading from a .txt file into a string variable, after which i'm trying to check specific spots in that for what they contain. I tried a switch like so
switch (map[2][4])
{
case "x"; something;break;
etc.
but this doesn't work, because switch (and if) only work for integers apparently. Is there a way to get around this, or something else I should be using here?
thanks in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Single quotes around a character represents a character constant which is an integer constant (of type int in C, and char in C++) and can be used with switch. Double quotes makes it a literal string constant, which has type const char* pointing to a character array and is not therefore an integer.
Of course I am assuming that map[2][4] references a single character. You trimmed the code rather too much to know for sure! Don't do that. Preferably poste complete compilable code, but we at least need to see the declarations of all variables involved.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, quick question.
I'm reading from a .txt file into a string variable, after which i'm trying to check specific spots in that for what they contain. I tried a switch like so
switch (map[2][4])
{
case "x"; something;break;
etc.
but this doesn't work, because switch (and if) only work for integers apparently. Is there a way to get around this, or something else I should be using here?
thanks in advance.
worked great. thank you.
case 'x'; something;break;
Single quotes around a character represents a character constant which is an integer constant (of type int in C, and char in C++) and can be used with switch. Double quotes makes it a literal string constant, which has type const char* pointing to a character array and is not therefore an integer.
Of course I am assuming that map[2][4] references a single character. You trimmed the code rather too much to know for sure! Don't do that. Preferably poste complete compilable code, but we at least need to see the declarations of all variables involved.
Clifford