But now I have another problem, it doesn't work the way I
Expected it to.
I am trying to make a clock. I got the numbers and the digits to work, but the system("cls" statement refreshes faster than the code posts the numbers, so instead I only see little bits and pieces of numbers once in a while.
Is there a way that the numbers will refresh over the top of the previous post, so that it will look like the clock is changing numbers in the same place?
if you won't use curses or slang for a better formatting of output, you can go by \n and \t to the place you want to fprintf the numbers and sleep( 1 ) between each call of showing the time.
1. Write the time
2. Pause for 1 sec.
3. Clear the screen
4. repeat
This is the quick and dirty way, though, but I don't know what curses or slang are, so you may want to look into that. Maybe noka will post some more info about where to read up on it...
sorry folks,
thought everybody would know all about curses and slang.
try the excellent 'Writing Programs with NCURSES'
by Eric S. Raymond and Zeyd M. Ben-Halim for a start with curses.
S-lang is a C-like programming language, designed to be embedded in programs. It provides standard screen handling functions, similar to curses.
if you like curses then try the curses development kid written by Mike Glover.
i know everybody wants a gui like M$-Windows, but this is a c++: unix forum and the customers i'm programming for use terminal i/o. ;-)
noka
first of all i think u just need to fflush your output buffers (stdout or cout) that would take care of the no. being o/p (visibly) to screen. Also call the clear b4 u print and not after u print in ur processing loop. i don't think giving a pause is the correct way to go about it.
secondly using system calls like "clear" is depending too much on the system settings( think @ someone replacing `which clear` by a shell script to copy bash and then call clear.orig!! u would never know of this hack!!)... hence, u wouldn't want to do so if u r running root or suid bit set programs.. (if u care) so a better way is to look in to the os specific tty header files and use that function appropriately.. (start with `man -a stty` on unix)
u can ofcourse avoid all this pain by using ncurses library !!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.