专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »C语言教程 » 用c编写文本文件:用c编写日历文件代码 »正文

用c编写文本文件:用c编写日历文件代码

来源: 发布时间:星期四, 2009年2月12日 浏览:315次 评论:0


/*
在中调试运行通过.
*/

#
#
#
#

typedefstruct
{
unsignedcharday;
unsignedcharmonth;
unsignedyear;
}T_MFW_DATE;
typedefstruct
{
T_MFW_DATEdate;/*记录日期*/
}t_cldrecord;
typedefstruct
{
T_MFW_DATEtoday_date;/*在中没有作用*/
T_MFW_DATEcursor_date;

days_map[6][7];/*日期地图*/

}t_cld_data;
t_cld_data*cld_data;
voidcld_get_days_map(void);
void(void)
{
i,j;
cld_data=(t_cld_data*)malloc((t_cld_data));

cld_data->cursor_date.day=20;
while(1)
{
charbuf[20];
char*p;
mem(buf,0,20);
prf(\"yearmonth:\");
gets(buf);
(buf[0]’q’);
cld_data->cursor_date.year=strtod(buf,&p);
p;
cld_data->cursor_date.month=strtod(p,&p);
prf(\"year%dmonth%d\",(cld_data->cursor_date.year),(cld_data->cursor_date.month));

cld_get_days_map;
prf(\"motuwthfrsasu\");
for(j=0;j<6;j)
{
prf(\"\");
for(i=0;i<7;i)
{
prf(\"%i\",cld_data->days_map[j][i]);
}
prf(\"\");
}
}
//getchar;
}
/*
检查日期是否合法
合法返回1否则返回0
*/
check_date(T_MFW_DATEdate)
{
charmonth_days=;
/*大于2000年小于2100年,月份合法*/
(date.year<2000||date.year>=2100||date.month<1||date.month>12)
{
0;
}
/*day合法*/
(date.day<1)0;
(date.day>month_days[date.month-1])0;
(date.month2)
{
(date.year%4!=0)
{
(date.day29)0;
}
}
1;
}
/*
功能:得到每个月第天是星期几
星期 2 3 4 5 6日
返回值:1234567

如果返回为0则出错
*/
get_weekday_of_month(T_MFW_DATEcursor_date)
{
day;
/*参照1997年1月1日,参数cursor_date从2000年1月1日到2099年1月1日*/
//charmonth_days={31,28,31,30,31,30,31,31,30,31,30,31};
this_year_days={0,31,59,90,120,151,181,212,243,273,304,334}; [Page]
cursor_year_days=this_year_days[cursor_date.month-1]+(cursor_date.day=1);
comp_days=(cursor_date.year-1997)*365+cursor_year_days;

i=(cursor_date.year-1997)/4;
comp_days=comp_days+i*1;

(cursor_date.month>2)
{
(cursor_date.year%40)
{
comp_days1;
}
}

(cursor_date.day>2098)0;

day=comp_days%7;
/*1997年1月1日是星期 3*/
day=(day+2)%7;
(day0)day=7;
day;
}
/*
根据参数值,得到该年该月有多少天.
返回值:该月天数
*/
count_days_of_month(T_MFW_DATEcursor_date)
{
charmonth_days=;
unsignedcharday=cld_data->cursor_date.day;
unsignedcharmonth=cld_data->cursor_date.month;
unsignedyear=cld_data->cursor_date.year;

(month!=2)
{
month_days[month-1];
}

{
(year%4!=0)
{
28;
}
(year%40)
{
(year%1000)
{
(year%4000)
{
29;
}
28;
}
29;
}
}
}
/*
得到日期地图,保存到全局结构变量cld_data成员变量days_map中.
*/
voidcld_get_days_map(void)
{
i;
day;
T_MFW_DATEcursor_date=cld_data->cursor_date;
*map_p=cld_data->days_map[0];
days_count;
weekday;
for(i=0;i<6*7;i)
{
map_p[i]=0;
}
(check_date(cld_data->cursor_date)0);
days_count=count_days_of_month(cld_data->cursor_date);


weekday=get_weekday_of_month(cld_data->cursor_date);
day=1;
for(i=weekday-1;i<days_count+weekday-1;i)
{
map_p[i]=day;
day;
}
}
0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: