In the following code, the program stops without any errors when I assign it's members values using scanf.
#include <stdio.h>
typedef struct {
int hours, minutes, seconds;
} Time;
int main (void) {
Time getTime (void);
Time time;
time = getTime();
printf ("%i:%i:%i", time.hours, time.minutes, time.seconds);
}
Time getTime (void) {
Time time;
printf ("Enter time (hh:mm:ss): ");
scanf ("%i:%i:%i", time.hours, time.minutes, time.seconds);
return time;
}
A sample of the output:
Enter time (hh:mm:ss): 12:12:12 - then the program stops executing
When I add \n to the last printf to flush the buffer, it still doesn't change anything.
I've tried to initialize both structures with default values but it made no difference i.e. Time time = {0, 0, 0};