/* This is the thirteenth lab of Lab EE107
The purpose of this lab to illustrate arrays of structures.

Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: April 23rd, 2024.
*/

// Structure definition for time
struct time_EU
{
    int hour_EU;
    int minutes_EU;
    int seconds_EU;
};

// Function to update time
struct time_EU timeUpdate_EU(struct time_EU now_EU)
{
    // Increment seconds
    ++now_EU.seconds_EU;
    // Check if seconds reached 60 for next minute
    if (now_EU.seconds_EU == 60) { // next minute
        now_EU.seconds_EU = 0;
        ++now_EU.minutes_EU;
    }
    // Check if minutes reached 60 for next hour
    if (now_EU.minutes_EU == 60) { // next hour
        now_EU.minutes_EU = 0;
        ++now_EU.hour_EU;
    }
    // Check if hour reached 24 for midnight
    if (now_EU.hour_EU == 24) // midnight
        now_EU.hour_EU = 0;
    
    // Return updated time
    return now_EU;
}


// Program to illustrate arrays of structures
#include <stdio.h>


// Main function
int main(void)
{
    // Declaration of timeUpdate function
    struct time_EU timeUpdate_EU(struct time_EU now_EU);
    // Test times array initialization
    struct time_EU testTimes_EU[5] =
    { { 11, 59, 59 }, { 12, 0, 0 }, { 1, 29, 59 },
      { 23, 59, 59 }, { 19, 12, 27 } };
    int i;
    // Loop through test times
    for (i = 0; i < 5; ++i) {
        // Print current time
        printf("Time is %.2i:%.2i:%.2i", testTimes_EU[i].hour_EU, 
               testTimes_EU[i].minutes_EU, testTimes_EU[i].seconds_EU);
        // Update time
        testTimes_EU[i] = timeUpdate_EU(testTimes_EU[i]);
        // Print time after one second
        printf(" ...one second later it's %.2i:%.2i:%.2i\n",
               testTimes_EU[i].hour_EU, testTimes_EU[i].minutes_EU, 
               testTimes_EU[i].seconds_EU);
    }
    // Return 0 to indicate successful execution
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: