Hey guys im trying to exstract the hour from the system clock and then trying to fill it in the clock2 array so i can display it like an actual clock. But when i display the clock it has to print
'H' on the hour and 'm' for the minutes. Iv done something similar just before but im having trouble with doing it from the system time.
So far the function shows this..
for example it prints
Sat Feb 17 15:17:10 EST 2007
then it displays a round clock with hours 1 -12
[code
say if its one oclock it will print 2 HH on it i have to do same thing for minutes
what can i do to fill the array with the system hour and minutes not sure if this is correct
its not working but i thought maybe i could copy ptr into hour but only copy %I which is the hour then put that in the array
/* updating the system hour within the clock array */
/* strftime(hour, 100, "%I", ptr); */
clock2[hr[hour]][hc[hour]] = hs;
clock2[hr[hour]][hc[hour]+ 1] = hs;
[/code]
Code:void displayClock2(int * optionStats) { /*declarations*/ struct tm *ptr; time_t lt; int i, j; int tm_min; int tm_hour; char str[80]; char hour[30]; char minutes[30]; char clock2[9][20] = { /* The array to hold the hard-coded clock */ " 12 ", " 11 01 ", " 10 02 ", " ", "09 . 03 ", " ", " 08 04 ", " 07 05 ", " 06 " }; /* Row and column numbers in clock array for hour positions. For * example, the "06" in the clock display is stored at position * [8, 8] in the clock matrix (see above) */ const int hr[13] = {0, 1, 2, 4, 6, 7, 8, 7, 6, 4, 2, 1, 0}; const int hc[13] = {0, 13, 15, 16, 15, 13, 8, 3, 1, 0, 1, 3, 8}; /* Hour and minute codes */ const char hs = 'H', ms = 'm'; lt = time(NULL); ptr = localtime(<); strftime(str, 100, "%a %b %d %X %Z %Y", ptr); /* copies ptr time struct into str string then formats string to day month day of month time then time zone then year*/ printf("\n"); printf(str); printf("\n"); /* once the struct gets copied into our formatted string it can get printed out to the screen*/ /* updating the system hour within the clock array*/ /* strftime(hour, 100, "%I", ptr); */ clock2[hr[hour]][hc[hour]] = hs; clock2[hr[hour]][hc[hour]+ 1] = hs; /* Display the clock */ for (i = 0; i < 9; i++) { for (j = 0; j < 19; j++) printf("%c", clock2[i][j]); printf("\n"); } printf("\n"); }



LinkBack URL
About LinkBacks


