LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 06-25-2004, 08:31 PM   #1
name_in_use450
Member
 
Registered: Jun 2004
Location: United States
Distribution: slackware 10.0 mostly; used many
Posts: 109

Rep: Reputation: 15
escape sequence help in C


Hey I hope someone can help me with this little problem. Web searches have come up dry. I do my programming in Linux by the way... :-)

code example:

int main()
{
time_t calendar_time;
struct tm *local_time;
calendar_time=time(NULL);
local_time=localtime(&calendar_time);
/*display time*/
printf("time: %s\WHATGOESHERE", asctime(local_time));
main();
return 0;
}

I want to print OVER the SAME line. If i use \n or the like i obviously will get newlines--no want i want. Basically I am trying to print the time in a loop (in this case recursive function). If i print over and over the same line it will be a sort of clock.

So how would I do this? I am thinking there is some rarely used escape sequence that not many people know about. If this is the case please help me out and tell it to me :-D. If there is no escape sequence to do this, how else can I?

Thanks much.
 
Old 06-25-2004, 09:04 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 11,539

Rep: Reputation: 676Reputation: 676Reputation: 676Reputation: 676Reputation: 676Reputation: 676
\r is a carriage return.
 
Old 06-30-2004, 01:25 PM   #3
name_in_use450
Member
 
Registered: Jun 2004
Location: United States
Distribution: slackware 10.0 mostly; used many
Posts: 109

Original Poster
Rep: Reputation: 15
i know the \r and that doesnt do the trick
 
Old 06-30-2004, 01:33 PM   #4
EyesOnly
Member
 
Registered: Aug 2003
Location: The Netherlands
Distribution: SlackWare
Posts: 202

Rep: Reputation: 30
As far as I know, that isn't possible when using printf() .. (?)

but you could use ncurses.
 
Old 06-30-2004, 02:47 PM   #5
jwstric2
Member
 
Registered: Jan 2004
Posts: 105

Rep: Reputation: 15
execv clear before each print, simulates writing over top the previoyus val. Also, why not get a system time to begin with then set an alarm for every second to update the time and reprint it. The one you have is too cpu intense.
 
Old 06-30-2004, 03:03 PM   #6
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
If you're in console you can use ansi escape sequences to position the cursor. Also works in windowing, but you should use the windowing
system calls or ncurses.

http://www.dee.ufcg.edu.br/~rrbrandt/tools/ansi.html
 
Old 07-01-2004, 09:23 AM   #7
name_in_use450
Member
 
Registered: Jun 2004
Location: United States
Distribution: slackware 10.0 mostly; used many
Posts: 109

Original Poster
Rep: Reputation: 15
thanks. i will try your suggestions. I have been looking around and agree that this is impossible with just an escape in printf().
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i escape a / ??? Fascistchicken Linux - General 10 09-12-2004 11:28 AM
Escape! Wind0wR3fuge Linux - Newbie 6 07-11-2004 03:00 AM
escape sequence for changing color of prompt killer_bunny Linux - General 1 02-10-2004 07:40 PM
The Great Escape Treefrog Linux - Software 6 11-11-2003 06:56 AM
smiley face escape sequence problem mandrakeroot Programming 12 09-06-2003 06:11 PM


All times are GMT -5. The time now is 07:41 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration