/* * File: hours.c * ------------------------------------ * Test program to convert a time given in minutes into * separate values representing hours and minutes. The * program is written as an illustration of C's mechanism * for simulating call by reference. */ #include #include "genlib.h" #include "simpio.h" /* Constants */ #define MinutesPerHour 60 /* Function Prototypes */ void ConvertToHoursAndMinutes (int, int *, int *) ; /* Test Program */ main () { int time, hours, minutes ; printf("Test prgram to convert time values\n") ; printf("Enter a time duration in minutes: ") ; time = GetInteger() ; ConvertToHoursAndMinutes(time, &hours, &minutes) ; printf("HH:MM format: %d:%2d\n", hours, minutes) ; } /* * Function: ConvertToHoursAndMinutes * Usage: ConvertToHoursAndMinutes(time, &hours, &minutes) ; * --------------------------------------------------------- * Converts a time value given in minutes into the number * of hours and the remaining number of minutes. Note that * the last two arguments must be passed using their addresses * so that the function can correctly set those values. */ void ConvertToHoursAndMinutes (int time, int *pHours, int *pMinutes) { *pHours = time / MinutesPerHour ; *pMinutes = time % MinutesPerHour ; }