Though there are many threads on this matter, i cannot find one that addresses my question, apologies if im being thick. An important distinction is that my solution cannot use pointers. I've started the chapter on structures and the problem i am working on calls for a function that takes two arguments t1 and t2, which are two different times in the framework of a structure. ive reduced that code as much as possible, and am finding that the values of my struct items arent getting through to the function.
#include<stdio.h>
struct time
{
int hour;
int minute;
int second;
};
struct time t1 = {3, 45, 15};
struct time t2 = {9, 44, 03};
int main (void)
{
struct time elapsedTime(struct time t1,struct time t2);
return 0;
}
struct time elapsedTime(struct time t1,struct time t2)
{
printf ("%i:%i:%i\n", t1.hour, t1.minute, t1.second);
printf ("%i:%i:%i\n", t2.hour, t2.minute, t2.second);
return;
}
main, you wantelapsedTime(t1, t2);intmembers, passing by value is not unreasonable.struct time elapsedTime(struct time t1,struct time t2);is a declaration of the function. It's not necessary if the full definition precedesmain. Just as a matter of style, it's more common to put function declarations at file scope, outside any function.