程序代写CS代考 // DO NOT MODIFY – cscodehelp代写

// DO NOT MODIFY
//
// LCD Clock simulator. Read a # of seconds from the beginning of the
// day from the command line and show the results of running functions
// from clock_update.c on the screen. Makes use of functions from
// clock_clock.c

#include
#include
#include
#include “clock.h”

int main(int argc, char **argv){

if(argc < 2){ // Set TIME_OF_DAY_SEC to the actual time time_t rawtime; // Get raw time with system calls time( &rawtime ); struct tm *info; // Store broken down time info = localtime( &rawtime ); // Get a broken down time // Calculate the seconds since the beginning of the day TIME_OF_DAY_SEC = info->tm_sec + 60*info->tm_min + 60*60*info->tm_hour;
}
else{ // Set time based on argument given
TIME_OF_DAY_SEC = atoi(argv[1]);
}
printf(“TIME_OF_DAY_SEC set to: %d
”, TIME_OF_DAY_SEC);

int time_max = 24 * 60 * 60;
if(TIME_OF_DAY_SEC >= time_max){
printf(“Time %d exceeds max %d
”,TIME_OF_DAY_SEC,time_max);
return -1;
}

tod_t tod;
int result;

printf(“result = set_tod_from_secs( %5d, &tod );
”,TIME_OF_DAY_SEC);
result = set_tod_from_secs(TIME_OF_DAY_SEC, &tod);
printf(“result: %d
”,result);
printf(“tod = {
”);
printf(” .hours = %d
”,tod.hours);
printf(” .minutes = %d
”,tod.minutes);
printf(” .seconds = %d
”,tod.seconds);
printf(” .ampm = %d
”,tod.ampm);
printf(“}
”);
printf(“Simulated time is: %02d : %02d : %02d %s
”,
tod.hours,tod.minutes,tod.seconds,(tod.ampm==1 ? “am” : “pm”));

printf(“%s”, (result == 0) ? “” : “WARNING: Non-zero value returned
”);

int display = 0;
printf(“result = set_display_from_tod(tod, &display);
”);
result = set_display_from_tod(tod, &display);
printf(“result: %d
”, result);
printf(“display is
”);
printf(“bits: %s
”,bitstr(display, INT_BITS));
printf(“index: %s
”,bitstr_index(INT_BITS));

printf(“%s”, (result == 0) ? “” : “WARNING: Non-zero value returned
”);

printf(“
”);

printf(“result = clock_update();
”);
result = clock_update();
printf(“result: %d
”, result);
printf(“CLOCK_DISPLAY_PORT is
”);
printf(“bits: %s
”,bitstr(CLOCK_DISPLAY_PORT, INT_BITS));
printf(“index: %s
”,bitstr_index(INT_BITS));

printf(“%s”, (result == 0) ? “” : “WARNING: Non-zero value returned
”);

printf(“
”);

printf(“Clock Display:
”);
print_clock_display();

return 0;
}

Leave a Reply

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