[Klug-general] C problem with delay and erase in Ubuntu terminal & Code::Blocks.

Mike Evans mike at tandem.f9.co.uk
Tue Jul 31 21:11:05 UTC 2012


Malcolm,

My first thought was what a complicated and nasty way to delay.  That's
what the sleep() function is for.  It has the advantage of handing
control back to the operating system so that the CPU can be used for
something more constructive than checking the clock ever few ms.

However I think the reason your program doesn't function the way you
hoped is due to IO buffering.  Things that you write with printf to a
normal I/O stream will only actually be flushed to the device when a
certain number of characters have been printed - or when a carriage
return or newline is found in the stream.  Your problem is that the
return is what is you are sending after the delay.  Now bearing in mind
that it is 30 years since I've had to do anything like this and I'm
working from an increasingly unreliable memory  - I think you can change
the function of the stream with some function like ioctl(), or you may
be able to flush it explicitly some other way.  Alternatively look at
the lower level functions read() and write(), which I think are
unbuffered. 

Good luck,
Mike




More information about the Kent mailing list