Hey guys im making a clock program which displays the current time as a clock however say it 12 00 oclock it is suppose to print mH on the 12 its not printing in the correct spot.
Does anyone know why?
Code:void displayClock2(int * optionStats) { /*declarations*/ struct tm *ptr; time_t lt; int i, j; int tm_hour; int hour; int a; char str[80]; 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); /*hr = ptr -> tm_hour;*/ /* 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); strftime(minutes, 100, "%M", ptr); hour = (int) strtod(*ptr, hour); printf(hour); printf(minutes); */ hour = ptr->tm_hour %12; clock2[hr[hour]][hc[hour]+1] = hs; clock2[hr[hour]][hc[hour]] = hs; /* Round m to the nearest hour position */ a = ptr->tm_min % 5; if( a >= 3) { a = ptr->tm_min / 5 + 1; clock2[hr[a]][hc[a]] = hs; clock2[hr[a]][hc[a]+ 1] = hs; } else { a = ptr->tm_min / 5; } /*if the minutes are equal to a zero like 12 00 m should be placed onto 12*/ if(ptr->tm_min == 0) { ptr->tm_min =12; } /*if minutes fall onto the 60 m should b placed on the 12*/ if(ptr->tm_min ==60) { ptr->tm_min = 12; } /* displays the mh symbol when two hands coincide*/ clock2[hr[a]][hc[a]] = ms; clock2[hr[a]][hc[a]+ 1] = hs; /* 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



When you start a new thread on the same program, link to the old thread so that people know what has already been said about it.