Code should be written in C Write a program that uses the X library to display a
ID: 3818131 • Letter: C
Question
Code should be written in C
Write a program that uses the X library to display a clock. The program should use the ctime() function to obtain the current time. The time should be display as text in HH:MM:SS format, where HH is the current hour, MM is the current minute, and SS is the current second. The display should be updated once per second, controlled using the sleep() function. The time should be displayed using the XDrawString() function in the center of a window created by the program. The program should run indefinitely.Explanation / Answer
#include <stdio.h>
#include <time.h>
int main ()
{
time_t rawtime;
struct tm * timeinfo;
while(1)
{
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( " HH:MM:SS----%d:%d:%d ",timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec);
Sleep(1000);
}
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.