Two solutions:
1st w/o pointers, remember to grab the return value and declare your functions with the correct return type:
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int hour;
int minute;
int second;
} TIME;
TIME allTime ();
int main (void)
{
TIME totTime;
totTime = allTime();
printf("\n\n\nThe total elapsed time is: %2d hr(s),%2d min(s), and%2d sec(s)\n", totTime);
return 0;
}
TIME allTime ()
{
TIME beginTime;
TIME endTime;
TIME totTime;
printf("Calculate the total time between start and finish\n");
printf("\nEnter the start time (hh:mm:ss) and press <enter>: ");
scanf("%d:%d:%d", &beginTime.hour, &beginTime.minute, &beginTime.second);
printf("\nEnter the finish time (hh:mm:ss) and press <enter>: ");
scanf("%d:%d:%d", &endTime.hour, &endTime.minute, &endTime.second);
totTime.hour = endTime.hour - beginTime.hour;
totTime.minute = endTime.minute - beginTime.minute;
totTime.second = endTime.second - beginTime.second;
return totTime;
}
2nd solution w/ pointers:
Code:
void allTime (TIME*);
int main (void)
{
TIME tTime;
allTime(&tTime);
printf("\n\n\nThe total elapsed time is: %2d hr(s),%2d min(s), and%2d sec(s)\n", tTime);
return 0;
}
void allTime (TIME* totTime)
{
TIME beginTime;
TIME endTime;
printf("Calculate the total time between start and finish\n");
printf("\nEnter the start time (hh:mm:ss) and press <enter>: ");
scanf("%d:%d:%d", &beginTime.hour, &beginTime.minute, &beginTime.second);
printf("\nEnter the finish time (hh:mm:ss) and press <enter>: ");
scanf("%d:%d:%d", &endTime.hour, &endTime.minute, &endTime.second);
totTime->hour = endTime.hour - beginTime.hour;
totTime->minute = endTime.minute - beginTime.minute;
totTime->second = endTime.second - beginTime.second;
}