/* This is the twelveth lab of Lab EE107
The purpose of this lab for illustrating and determining the time of next second
using function and structures modified to that given the current time, the code
returns the time of one second ago.
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: April 16th, 2024.
*/
#include <stdio.h>
// Define a structure for time
struct time_EU {
int hour;
int minutes;
int seconds;
};
// Function prototype
struct time_EU timeOneSecondAgo_EU(struct time_EU now);
int main(void) {
struct time_EU timeOneSecondAgo_EU(struct time_EU now);
struct time_EU currentTime_EU, previousTime_EU;
// Get the current time from the user
printf("Enter the time (hh:mm:ss): ");
scanf("%i:%i:%i", ¤tTime_EU.hour, ¤tTime_EU.minutes, ¤tTime_EU.seconds);
// Get the time of one second ago
previousTime_EU = timeOneSecondAgo_EU(currentTime_EU);
// Print the time of one second ago
printf("Time of one second ago is %.2i:%.2i:%.2i\n", previousTime_EU.hour, previousTime_EU.minutes, previousTime_EU.seconds);
return 0;
}
// Function to return the time of one second ago
struct time_EU timeOneSecondAgo_EU(struct time_EU now) {
// If seconds is 0, set it to 59 and decrement minutes
--now.seconds; // Decrement hours
if (now.seconds == -1) {
now.seconds = 59;
--now.minutes; // Decrement minutes
// If minutes is 0, set it to 59 and decrement hours
if (now.minutes == -1) {
now.minutes = 59;
--now.hour; // Decrement seconds
// If hours is 0, set it to 23 (previous day)
if (now.hour == -1) {
now.hour = 23;
}
}
}
// Return the time of one second ago
return now;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: