我正在尝试创建一种“优雅”的方式来实时显示用户在自定义内核中输入的内容,这是我正在研究的68hc12。
#include "hc12sci.h"
#include "iomanip.h"
int main()
{
Hc12Sci hc12sci(sci0,16,36); // serial port, rxlen, txlen
ostream os(&hc12sci);
istream is(&hc12sci);
char cmd[16];
char c;
os << "hello world!" << endl;
while(1)
{
for(int i = 0; i<=15; i++)
{
is >> c
cmd[i] = c;
os << c << flush;
if(c == '\r') // test for carriage return
os << cmd << endl;
}
os << endl;
}
return 0;问题是,我敢肯定,它似乎从来没有进入回车if语句。我是在Ubuntu中构建的,有没有关于if语句的错误之处?如果你需要更多信息,请告诉我。谢谢。
发布于 2013-02-18 13:12:45
我能看到的第一个问题是,您正在检查回车。Ubuntu/Unix不使用回车作为行尾。而是使用换行符:'\n‘(0x0A)。
所以试着把它改成这样:
if ( c == '\n')https://stackoverflow.com/questions/14929670
复制相似问题