Counting days between 2 dates

This is a discussion on Counting days between 2 dates within the C Programming forums, part of the General Programming Boards category; Hello everyone,
My program is to count total days between two entered by user dates, during the compilation I am ...

Now I am having a trouble with count_days function, it gives wrong result. To me the calculation seems to be right, but according to result it's not. Actually I was counting all days from beging to the end for first year, so if date entered by user was 2/15/2004, I was counting how many days passed from 1/1/1- to 2/15/2004 same thing with ending year. Then I just had to find different of days between those days.

here si the function

Code:

long int count_days(void)
{
int A[13]={ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
int B[13]={ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
int a, b;
int i, count, leap_count=0;
long int days1=0, days2=0, total_days;
int days_per_year=365;
for(i=1; i<begin.year; ++i)//how many days in a full years before last begining year
{
count=isLeapYear(i);
leap_count+=count;
days1+=days_per_year;
}
days1+=leap_count;// adding amount of leap years passed from year 1 to (begin.year-1)
leap_count=0;
for(i=1; i<end.year; ++i) //how many days in a in a full years before last end year
{
count=isLeapYear(i);
leap_count+=count;
days2+=days_per_year;
}
days2+=leap_count; //adding amount of leap years passed from ...
a=isLeapYear(begin.year);
b=isLeapYear(end.year);
if(a==1) // if egin year isleap year
{
days1=days1+B[begin.month-1]+begin.day; // amount of days before begin.year + days past in a begin.year
}
else if(b==1) // if end year is leap year
{
days2=days2+B[end.month-1]+end.day;
}
else // if not leap year
{
days1=days1+A[begin.month-1]+begin.day;
days2=days2+A[end.month-1]+end.day;
}
total_days=days2-days1; // amount of days between first and second years
return total_days;
}

You could also do this with an array of the days in that month, and a loop. First, subtract the start day of the starting month from the days in that month. Then while you aren't at the right year add each years worth of days (allowing for leap year). Once you're in the right year, while you're not at the right month, add those months' day count in. Then add the date in the last month.

Thank you guys, I wasn't allowed to use any library except stdio.h.
I am done with this program, I deleted that function and wrote another one which is actually came out to be simpler and it's working.
Thanks again for your support.