سؤال

I'm trying to create and "elegant" way of displaying in real time what a user inputs into a custom kernel, for a 68hc12, I'm working on.

#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;

The problem, of many I'm sure, is it never seems to enter the carriage return if statement. I'm building this in Ubuntu, any though on what I'm doing wrong with the if statement? let me know if you need additional info. Thanks.

هل كانت مفيدة؟

المحلول

First problem I can see is that you are checking for carriage returns. Ubuntu/Unix does not use carriage returns for the end of lines. It instead it uses line feed: '\n' (0x0A).

So try changing it to this:

if ( c == '\n')
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top