passing structure to function
Hey all, thanks for the help (again)
I'm just returning link.year to try and get a working number after the function is called but it won't work. Do I somehow need to add link.year inside the struct_function function to initialize link.year, it's returning as '0' when i run the program no matter what yyyy I insert.
I will be coding the forumla inside the struct_function function once i can see that all the structure variables date_one.month, date_one.day, date_one.year can be activated through the printf function after I run the program. Thanks for the help
This
Code:
// EX_2.c Chapter 8 Exercise #2
// compute two date
// August 8, 2014
// February 22, 2015
#include <stdio.h>
struct my_struct
{
int month;
int day;
int year;
};
int main(void)
{
int struct_function (struct my_struct link);
struct my_struct date_one, date_two;
printf("Enter date #1: (mm dd yyyy): ");
scanf("%i/%i/%i", &date_one.month, &date_one.day, &date_one.year);
/*
printf("Enter date #2: (mm dd yyyy): ");
scanf("%i/%i/%i", &date_two.month, &date_two.day, &date_two.year);
*/
// return integer
printf("%i\n", struct_function(date_one));
// printf("%i", struct_function(date_two));
return 0;
}
int struct_function (struct my_struct link)
{
// N = 1461 * f(year, month) / 4 + 153 * g(month) / 5 + 3;`
int sum;
if (link.month <= 2)
{
link.year -= 1;
link.month += 13;
}
else if (link.month > 2)
{
link.year = link.year;
link.month += 1;
}
return link.year;
}