0

I just wandered if there is a way to constantly update the time once it has been displayed on a console application. I am using the following code to display the time:

time_t rawtime;
	struct tm * timeinfo;

	time ( &rawtime );
	timeinfo = localtime ( &rawtime );
	printf ("The current time is %s\n", asctime (timeinfo));

Thanks in advance for any help,
climberboy

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Ancient Dragon
0

put that in its own thread so that other processing can be done. In the thread put the code in an infinite loop. Call Sleep(1000) inside the loop so that the thread waiks up only once per second. Also you might want to add '\r' at the beginning of the string. printf("\rCurrent ..."); Hopefully there is no other output in the program because if there is then '\r' won't work because the cursor may be on some other line. You could, nowever, use win32 api console functions to move the cursor to the desired line on the screen.

Edited by Ancient Dragon: n/a

0

I'm not really sure how to put it in it's own thread..... can you recommend a good resource that can help?

0

Try to use this if it helps...

#include <iostream>
#include <string>
#include <time.h>

using namespace std;
  
int main()
{
    char T[9];

    _strtime_s(T);

	cout<<T;
	
    return (0);
}

But your problem is still there... You can solve it by using an iteration algorithm using "goto" OR you can use timers, I have used timers in windows forms and they work very well, not sure if it is applicable to this problem.

Edited by Software guy: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.