Menu

[Solved]Add Code Make Time String Bounce Around Screen Moving Different Random Line Column Time Di Q37281943

Add to this code to make it so that your time string should”bounce around” the screen by moving to a different, random line& column each time it is displayed. When outputting a new time,you will have to erase the old location first. Also, make sure youavoid overwriting your message from step 2 or allowing your timestring to wrap off the end of a line.

#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#define SIZE 256

unsigned int alarm(unsigned int seconds);
void timeout(int); // declare timeout() as a void function
int alrm_cnt = 0;
char timestr[SIZE];
time_t curtime;
struct tm *loctime;

int main()
{
signal(SIGALRM, timeout);   // alarm timer routine
alarm(1);                  // set alarm timer for 1 second
/*** an infinite loop! ***/
while(1)
{
    pause(); // suspend process ’till signal
}

}
// asynchronously called function to handle programmed timeoutalarm
void timeout(int signo)
{
curtime = time (NULL); //Get the current time.
loctime = localtime (&curtime); //Convert it to local timerepresentation.
strftime (timestr,SIZE, “%I:%M:%S %pn”, loctime);
fputs (timestr, stdout);
fflush(stdout);
   signal(SIGALRM, timeout); // keep signal handler intact
   alarm(1); // rearm process timer for next interval

}

Expert Answer


Answer to Add to this code to make it so that your time string should “bounce around” the screen by moving to a different, random … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *