Fixed version of qtime.c

Ade Lovett ade at cs.warwick.ac.uk
Sat Sep 16 00:47:30 AEST 1989


After all those problems with NULL != "" in qtime, there does in fact appear
to be a *real* bug in qtime.

As Rchard Wexelblat <rwex at org.ida.cs> pointed out (thank you :-), any time
where the minutes are greater than 30 causes the wrong hour to be printed out.
E.g.
	7:35 will give 25 minutes to seven

Oops. Here is the amended qtime.c

aDe

---- cut here ----
/* qtime.c	Displays time in real English, also chimes
**
** 09/89	Ade Lovett	Complete rewrite
** 04/86	Mark Dapoz	Converted to C for UNIX
** 12/79-12/82	Mike Cowlishaw
**
*/
#include <stdio.h>
#include <sys/types.h>
#include <time.h>

char *minutesaying[] = {
    "","just after ","a little after ","nearly ","almost "
};
char *fiveminsaying[] = {
    "","five past ","ten past ","a quarter past ","twenty past ",
    "twenty-five past ","half past ","twenty-five to ","twenty to ",
    "a quarter to ","ten to ","five to ",""
};
char *hoursaying[] = {
    "one","two","three","four","five","six","seven","eight","nine",
    "ten","eleven",""
};

void main()
{
    char qtime[200];
    int i, hr, mn;
    time_t clock, time();
    struct tm *tm, *localtime();

    time(&clock);
    tm = localtime(&clock);
    hr = tm->tm_hour;
    mn = tm->tm_min+(tm->tm_sec>29);

    strcpy(qtime, "It's ");
    strcat(qtime, minutesaying[mn%5]);
    strcat(qtime, fiveminsaying[mn/5+(mn%5>2)]);
    
    if (hr%12) {
	strcat(qtime, hoursaying[(hr -= (hr>12)*12+(mn<33))]);
	strcat(qtime, (mn%60) ? "." : " o'clock.");
    } else {
	strcat(qtime, (hr == 12) ? "Noon" : "Midnight");
	hr = 12;
    }
    
    if (!(mn%15))
	if (mn%60)
	    printf("(Ding-Dong!)\n\n");
	else {
	    printf("(");
	    for (i=hr; i>=0; i--)
		printf("Bong%s",(i==0 ? "!)\n\n" : ","));
	}
    printf("%s\n",qtime);
}
--
+--- Ade Lovett --------+- ade at cs.warwick.ac.uk ------ +44 932 842478 -------+
| Computer Science      |  INTERNET: ade%cs.warwick.ac.uk at nsfnet-relay.ac.uk |
| Warwick University    |  UUCP    : ...!mcvax!ukc!warwick!ade               |
| Coventry CV4 7AL, UK  |  BITNET  : ade%uk.ac.warwick.cs at ukacrl             |
+-----------------------+----------------------------------------------------+



More information about the Alt.sources mailing list