. Advertisement .
..3..
. Advertisement .
..4..
I’m building a new program, but when I run it, an error pops up. The error displayed is as follows:
warning: comparison between pointer and integer
('int' and 'char *')
I have tried several workarounds, but they still do not get the desired results. If you have come across this situation and have a solution for the “warning: comparison between pointer and integer” problem, please let me know. Here is what I do:
const char* message = "hi";
//I then loop through the message and I get an error in the below if statement.
if (*message == "\0") {
...//do something
}
Thanks!
The cause: The message “comparison between pointer (string) and integer (character)” indicates that you are attempting to make a comparison between a character and a string.
Solution: In C, single characters are delimited by simple quotes, whereas strings are delimited by double quotations. Therefore, instead of:
you should write:
This
"\0"
string is not a character. A character uses single quotes, like'\0'
.