workaround for C++ printf carriage return
I am new to Linux and am porting a C++ program from ROM-DOS to Linux. I have managed to get everything working except the screen display (text screen only).
The programme is reading data from an external input and I want to update the screen with the latest readings. I do not want the screen to scroll (i.e. linefeed). I want to keep updating the values on the same line. In the ROM-DOS version I was able to do this by using the \r (carriage return) escape sequence. In the Linux program I don't get anything displayed when I use \r. The display appears when I change to using \n (newline) but then a new line of text is generated for every printf call which is not what I want. Is there another way of doing this? |
Hi,
I think that the problem with \r is that, by default, the stdout is not flushed until a \n is found. So, what you can do is flush the stdout manually everytime you want to update the screen so it gets display. This is a simple example that worked on my PC: Code:
#include <stdio.h> If you want to make more advanced text interface, then you should turn into the ncurses library which lets you do fancy things in text mode. Hope this is useful. Cheers! |
Excellent! That is exactly what I was looking for. Thanks very much.
|
All times are GMT -5. The time now is 04:33 AM. |