c语言输出日历,月历

  • 格式:txt
  • 大小:6.48 KB
  • 文档页数:3
}
return 0;
}
int is_leak_year(int year)
{
int is_leak;
if(year%4==0)
{
if(year%100==0 && year%400==0)
{
is_leak=1;
}
else if(year%100!=0)
{
is_leak=1;
{
m=14;
c=(int)((year-1)/100);
y=year-1-c*100;
}
else
{
m=month+1;
c=(int)(year/100);
y=year-c*100;
}
month=convert_str_to_int(argc[2],strlen(argc[2]))-1;
day=1;//默认为一号
weekday=week_calculate(year,month,day);
}
else if(argv==4)//输入参数为月日年时
{
year=convert_str_to_int(argc[1],strlen(argc[1]));
day=today->tm_mday;
weekday=today->tm_wday;
prical=1;
}
else if(argv==2)//输入参数为两个时,打印帮助信息或出错信息
{
if(strcmp(argc[1],"-h")==0)
{
print_help();
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
const int month_day[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31},
int pow_10(int p);
void print_help(void);//打印帮助信息
int main(int argv,char **argc)
{
struct tm *today;
time_t t1;
int leak;//是否为闰年
int year,month,day,weekday;//年月日星期
}
else
{
fprintf(stderr,"不能识别参数,帮助用-h参数");
exit(EXIT_FAILURE);
}
}
else if(argv==3)//输入参数为年月时
{
year=convert_str_to_int(argc[1],strlen(argc[1]));
};//月的天数
//const char *week_day[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat",};
const char *week_day[7]={"日","一","二","三","四","五","六",};
void print_calendar1(int monthday,int mon_first_wd);//打印有输入参数的日历
int convert_str_to_int(char str[],int len);//字符串转化为整数
int week_calculate(int year,int month,int day);//计算输入年月日的星期序号
month=convert_str_to_int(argc[2],strlen(argc[2]))-1;
day=convert_str_to_int(argc[3],strlen(argc[3]));
weekday=week_calculate(year,month,day);
}
else
{
int i;
for(i=0;i<7;i++)
{
printf("%s",week_day[i]);
if(i<6)
{
printf(" ");
}
}
printf("\n");
for(i=0;i<mon_first_wd;i++)//打印1号前的空格
}
}
printf("\n");
}
int convert_str_to_int(char str[],int len)//将年月日字符串转化为整型数据
{
int i;
int j=0;
for(i=0;i<len;i++)
{
j+=(int)(str[i]-'0')*pow_10(len-i-1);
算)
d:日
w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1
*/
int y,c,m,w;
int week;
if(month==0)
{
m=13;
c=(int)((year-1)/100);
y=year-1-c*100;
}
else if(month==1)
{
printf(" ");
}
for(i=1;i<=monthday;i++)//打印日期
{
if(i!=today)
{
printf("%2d ",i);
}
else
{
printf("\033[7m%2d\033[0m ",i);//linux中反白显示
const char *month_name[12]={"一","二","三","四","五","六","七","八","九","十","十一","十二",};
int is_leak_year(int year);//判断是否为闰年
void print_calendar0(int monthday,int mon_first_wd,int day);//打印默认参数日历
for(i=0;i<7;i++)
{
printf("%s",week_day[i]);
if(i<6)
{
printf(" ");
}
}
printf("\n");
for(i=0;i<mon_first_wd;i++)//打印1号前的空格
w=y+(int)(y/4)+(int)(c/4)-2*c+(int)(26*(m+1)/10)+day-1;
//计算星期序号0~6
//printf("%d\n",w);
if((w%7)<0)
printf(" %d年%s月\n",year,month_name[month]);
/*打印月历*/
if(prical)
{
print_calendar0(month_day[leak][month],mon_first_day_week,day);
}
else
{
print_calendar1(month_day[leak][month],mon_first_day_week);
exit(EXIT_FAILURE);
}
/*if(month==1)
{
if(leak)
{
if(day>29)
{
fprintf(stderr,"%4d年是闰年,2月只有29天\n",year);
exit(EXIT_FAILURE);
{
/*计算星期序号用蔡勒公式,该公式仅适用于1582年10月15日之后
w:星期;对w取余运算,week=w%7,如果w<0,week=w%7+7,即可得到星期的序号
c:世纪减1(年份前两位数)
y:年(后两位数)
m:月(m大于等于3,小于等于14,即在蔡勒公式中,某年的1、2月要看作
上一年的13、14月来计算,比如2003年1月1日要看作2002年的13月1日来计
}
}*/
//mon_first_day_week=weekday-(day-1)%7;
if((mon_first_day_week=weekday-(day-1)%7)<0)
{
mon_first_day_week+=7;
}
// printf("weekday:%d,%d\n",weekday,mon_first_day_week);
}
else
{
is_leak=0;
}
}
else
{
is_leak=0;
}
return is_leak;
}
void print_calendar0(int monthday,int mon_first_wd,int today)//打印默认月历,高亮显示当前日期

下载文档原格式

  / 3

相关主题