![]() |
![]() |
![]() |
![]() |
![]() |
|
Finally, you can hide all the detail in a function:
/* Define global time variables */
int year, month, day, hour, minute;
/* Define function to establish time-variable values */
void assign_time_variables ( ) {
/* Declare variable to hold elapsed seconds since 1970 */
time_t elapsed_seconds;
/* Declare pointer to an object containing time information */
struct tm *time_structure_pointer;
/* Fetch elapsed seconds from operating system */
time(&elapsed_seconds);
/* Use elapsed seconds to update time-structure object */
time_structure_pointer = localtime (&elapsed_seconds);
/* Extract useful information from the time structure */
year = 1900 + time_structure_pointer -> tm_year;
month = time_structure_pointer -> tm_mon;
day = time_structure_pointer -> tm_mday;
hour = time_structure_pointer -> tm_hour;
minute = time_structure_pointer -> tm_min;
}