当我遍历字符指针并检查指针何时到达空终止符时,我收到警告。
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
}
我得到的错误是:
warning: comparison between pointer and integer
('int' and 'char *')
我认为 message
前面的 *
取消引用消息,所以我得到消息指向哪里的值?顺便说一句,我不想使用库函数strcmp
。
最佳答案
应该是
if (*message == '\0')
在 C 中,单引号分隔单个字符,而双引号用于字符串。
关于c - 指针和整数之间的警告比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32510218/