"Michael" <mi*********@yahoo.comwrites:
I have the following in some code:
char temp[MAX_INPUT_LENGTH];
....stuff....
for(i = 0; i < MAX_INPUT_LENGTH; i++){
if(temp[i] == ":"){
...stuff....
}
but when I have a string with ':' in it, the 'if' doesn't match. Why?
As others have pointed out, temp[i] is a char, and ":" is a string
(which decays to a pointer to char in this context).
Trying to compare a char and a char* for equality is a constraint
violation, requiring a diagnostic (at least a warning, more likely a
fatal error).
If your compiler didn't complain, you're using it in a mode where it
doesn't warn you about serious errors. Find out how to increase its
diagnostic level. Your compiler can catch a lot of errors for you if
you let it.
(If it did complain, then your compiler already answered your
question, and you shouldn't have needed to ask us. If you didn't
understand the error message, perhaps something like "warning:
comparison between pointer and integer", you could have shown it to
us.)
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.