Character comparison NIGHTMARE
-
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...
-
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...
I think you reversed the parameters. char *strchr(const char *s, int c); Kevin
-
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...
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
-
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...
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...
-
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...
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
-
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
Thanks, David!:-D I've just fallen into that trap myself, a couple of times before.:( INTP Every thing is relative...
-
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...
-
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...
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...
-
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...
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 ofstringIndex
in the watch window. That is if you do not want to do it manualy in the code itself. INTP Every thing is relative...