Arduino C 没有进入循环?
char* lastfeedbuffer[3];
void lastfeed_receive(){
while(Serial.available() >= LASTFEED_LEN ){
char c = Serial.read();
if (c == LASTFEED_HEAD){
for (int i = 0; i < LASTFEED_LEN - 1; i++){
lastfeedbuffer[i] = Serial.read();
}
}
}
Serial.println(lastfeedbuffer);
if (lastfeedbuffer == "00"){
Serial.println("asdf");
}
}
我不明白为什么以下代码不打印 asdf
。 Serial.println(lastfeedbuffer)
打印 00
,这意味着它应该进入循环,为什么不呢?
char* lastfeedbuffer[3];
void lastfeed_receive(){
while(Serial.available() >= LASTFEED_LEN ){
char c = Serial.read();
if (c == LASTFEED_HEAD){
for (int i = 0; i < LASTFEED_LEN - 1; i++){
lastfeedbuffer[i] = Serial.read();
}
}
}
Serial.println(lastfeedbuffer);
if (lastfeedbuffer == "00"){
Serial.println("asdf");
}
}
I don't understand why the following code is not printing the asdf
. the Serial.println(lastfeedbuffer)
prints 00
, which means it should go into the loop any ideas why it doesn't?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 strcmp(lastfeedbuffer, "00") == 0 - 您当前正在做的是比较两个不相关的指针。
另外,我相信您的实际代码中有
char lastfeedbuffer[3];
而不是char* lastfeedbuffer[3];
?Use
strcmp(lastfeedbuffer, "00") == 0
- What you're currently doing is to compare two unrelated pointers.Also, I believe you have
char lastfeedbuffer[3];
notchar* lastfeedbuffer[3];
in your actual code?