以结构指针作为函数参数

#include <iostream>
using namespace std;
struct date
{
 int day;
 int month;
 int year;
 int yeardays;
};
void days(struct date *pd);
void main()
{
 struct date ymd;
 cout << "Enter year/month/day:";
 cin >> ymd.year >> ymd.month >> ymd.day;
 days(&ymd);
 cout << "the passddays: " << ymd.yeardays;
}
void days(struct date *pd)
{
 static int day_tab[2][13]={
  {0,31,28,31,30,31,30,31,31,30,31,30,31},
  {0,31,29,31,30,31,30,31,31,30,31,30,31},
 };
 int i,Ip;
 pd -> yeardays = pd -> day;
 Ip = pd->year%4==0&&pd||pd->year%100!=0
  ||pd->year%400==0;
 for(i=1; i<pd->month; i++)
  pd->yeardays = pd->yeardays + day_tab[Ip][i];
}

posted @ 2013-10-07 15:38  Blackfog  阅读(201)  评论(0编辑  收藏  举报