Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Character comparison NIGHTMARE

Character comparison NIGHTMARE

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adonisv
    wrote on last edited by
    #1

    Any reason why this comparison should fail, CONSISTENLY??? Assuming the character at pToken->GetName()[stringIndex] is a - ???? :confused: else if (result = strchr("-",pToken->GetName()[stringIndex])) { // Equals Sign Operator = CNode::Minus; szIdString = "Minus"; bIsSymbol = true; } My other comparisons are working for semicolon and equals, for example. else if (result = strchr(";",pToken->GetName()[stringIndex])) { // Semicolon Operator = CNode::Semicolon; szIdString = "Semicolon"; bIsSymbol = true; } else if (result = strchr("=",pToken->GetName()[stringIndex])) { // Equals Sign Operator = CNode::Equals; szIdString = "Equals"; bIsSymbol = true; } I'm completely stuck on this... :~ Normality is a weakness...

    K D J 3 Replies Last reply
    0
    • A adonisv

      Any reason why this comparison should fail, CONSISTENLY??? Assuming the character at pToken->GetName()[stringIndex] is a - ???? :confused: else if (result = strchr("-",pToken->GetName()[stringIndex])) { // Equals Sign Operator = CNode::Minus; szIdString = "Minus"; bIsSymbol = true; } My other comparisons are working for semicolon and equals, for example. else if (result = strchr(";",pToken->GetName()[stringIndex])) { // Semicolon Operator = CNode::Semicolon; szIdString = "Semicolon"; bIsSymbol = true; } else if (result = strchr("=",pToken->GetName()[stringIndex])) { // Equals Sign Operator = CNode::Equals; szIdString = "Equals"; bIsSymbol = true; } I'm completely stuck on this... :~ Normality is a weakness...

      K Offline
      K Offline
      kevincwong
      wrote on last edited by
      #2

      I think you reversed the parameters. char *strchr(const char *s, int c); Kevin

      1 Reply Last reply
      0
      • A adonisv

        Any reason why this comparison should fail, CONSISTENLY??? Assuming the character at pToken->GetName()[stringIndex] is a - ???? :confused: else if (result = strchr("-",pToken->GetName()[stringIndex])) { // Equals Sign Operator = CNode::Minus; szIdString = "Minus"; bIsSymbol = true; } My other comparisons are working for semicolon and equals, for example. else if (result = strchr(";",pToken->GetName()[stringIndex])) { // Semicolon Operator = CNode::Semicolon; szIdString = "Semicolon"; bIsSymbol = true; } else if (result = strchr("=",pToken->GetName()[stringIndex])) { // Equals Sign Operator = CNode::Equals; szIdString = "Equals"; bIsSymbol = true; } I'm completely stuck on this... :~ Normality is a weakness...

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        adonisv wrote:

        else if (result = strchr("-",pToken->GetName()[stringIndex])) { // Equals Sign Operator = CNode::Minus; szIdString = "Minus"; bIsSymbol = true; }

        Why not break this up into more manageable statements, like:

        char c = pToken->GetName()[stringIndex];
        char *result = strchr("-", c);
        if (result != NULL)
        {
        ...
        }

        Now you can set a breakpoint on the first statement and single-step through them, noting the results along the way.


        "Take only what you need and leave the land as you found it." - Native American Proverb

        1 Reply Last reply
        0
        • A adonisv

          Any reason why this comparison should fail, CONSISTENLY??? Assuming the character at pToken->GetName()[stringIndex] is a - ???? :confused: else if (result = strchr("-",pToken->GetName()[stringIndex])) { // Equals Sign Operator = CNode::Minus; szIdString = "Minus"; bIsSymbol = true; } My other comparisons are working for semicolon and equals, for example. else if (result = strchr(";",pToken->GetName()[stringIndex])) { // Semicolon Operator = CNode::Semicolon; szIdString = "Semicolon"; bIsSymbol = true; } else if (result = strchr("=",pToken->GetName()[stringIndex])) { // Equals Sign Operator = CNode::Equals; szIdString = "Equals"; bIsSymbol = true; } I'm completely stuck on this... :~ Normality is a weakness...

          J Offline
          J Offline
          John R Shaw
          wrote on last edited by
          #4

          What is wrong with: if( '-' == pToken->GetName()[stringIndex] ) Or even:

          switch(pToken->GetName()[stringIndex]) {
          case '-':
          // do some thing
          break;
          case '=':
          // do some thing
          break;
          }

          INTP Every thing is relative...

          D A 3 Replies Last reply
          0
          • J John R Shaw

            What is wrong with: if( '-' == pToken->GetName()[stringIndex] ) Or even:

            switch(pToken->GetName()[stringIndex]) {
            case '-':
            // do some thing
            break;
            case '=':
            // do some thing
            break;
            }

            INTP Every thing is relative...

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Excellent advice, John! I feel so inadequate for not seeing that myself. :doh:


            "Take only what you need and leave the land as you found it." - Native American Proverb

            J 1 Reply Last reply
            0
            • D David Crow

              Excellent advice, John! I feel so inadequate for not seeing that myself. :doh:


              "Take only what you need and leave the land as you found it." - Native American Proverb

              J Offline
              J Offline
              John R Shaw
              wrote on last edited by
              #6

              Thanks, David!:-D I've just fallen into that trap myself, a couple of times before.:( INTP Every thing is relative...

              1 Reply Last reply
              0
              • J John R Shaw

                What is wrong with: if( '-' == pToken->GetName()[stringIndex] ) Or even:

                switch(pToken->GetName()[stringIndex]) {
                case '-':
                // do some thing
                break;
                case '=':
                // do some thing
                break;
                }

                INTP Every thing is relative...

                A Offline
                A Offline
                adonisv
                wrote on last edited by
                #7

                Nice solution, thanks! :-> Normality is a weakness...

                1 Reply Last reply
                0
                • J John R Shaw

                  What is wrong with: if( '-' == pToken->GetName()[stringIndex] ) Or even:

                  switch(pToken->GetName()[stringIndex]) {
                  case '-':
                  // do some thing
                  break;
                  case '=':
                  // do some thing
                  break;
                  }

                  INTP Every thing is relative...

                  A Offline
                  A Offline
                  adonisv
                  wrote on last edited by
                  #8

                  Well, none of those solutions worked. pToken 0x00325360 {m_id=0xfffffcf7 m_name=0x003253c8 "–" m_eType=None ...} This is what is showing up in the debugger. Am I comparing a character here or not. It keeps failing pretty consistently. It looks like a string. Normality is a weakness...

                  J 1 Reply Last reply
                  0
                  • A adonisv

                    Well, none of those solutions worked. pToken 0x00325360 {m_id=0xfffffcf7 m_name=0x003253c8 "–" m_eType=None ...} This is what is showing up in the debugger. Am I comparing a character here or not. It keeps failing pretty consistently. It looks like a string. Normality is a weakness...

                    J Offline
                    J Offline
                    John R Shaw
                    wrote on last edited by
                    #9

                    Sounds like may be the stringIndex is wrong. If not I am out of ideas. If you know the first character is '-' then run a test with stringIndex=0. You can atualy do this in the debugger, by stoping on the offending line and changing the value of stringIndex in the watch window. That is if you do not want to do it manualy in the code itself. INTP Every thing is relative...

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups