Menu

a little stuck

Bill Akin
2008-07-17
2012-09-26
  • Bill Akin

    Bill Akin - 2008-07-17

    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.

     
    • Bill Akin

      Bill Akin - 2008-07-17

      worked great. thank you.

       
    • cpns

      cpns - 2008-07-17

      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

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.