国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

用c寫的一個日歷文件

2019-11-17 05:48:58
字體:
來源:轉載
供稿:網友
/*
該程序在vc中調試運行通過.
*/
#include <stdio.h>
#include<malloc.h>
#include<string.h>
#include<stdlib.h>typedef strUCt
{
 unsigned char day;
 unsigned char month;
 unsigned short year;}T_MFW_DATE;
typedef struct
{
 T_MFW_DATE date;  /*記錄的日期*/
}t_cldrecord;typedef struct
{
 T_MFW_DATE today_date;  /*在程序中沒有作用*/
 T_MFW_DATE cursor_date;
 
 int days_map[6][7];   /*日期地圖*/
 
}t_cldmain_data;t_cldmain_data *cldmain_data;void cldmain_get_days_map(void);void main(void)
{
 int i,j;
 cldmain_data = (t_cldmain_data*)malloc(sizeof(t_cldmain_data));
 
 cldmain_data->cursor_date.day = 20;
 while(1)
 {
  char buf[20];
  char *p;
  memset(buf,0,20);    gets(buf);
  if(buf[0] == 'q')break;  cldmain_data->cursor_date.year = strtod(buf,&p);
  p ++;
  cldmain_data->cursor_date.month = strtod(p,&p);  printf("year %dmonth %d",(cldmain_data->cursor_date.year),(cldmain_data->cursor_date.month));
  
  cldmain_get_days_map();
  printf(" mo tu w th fr sa su");
  for(j = 0; j < 6; j ++)
  {
   printf(" ");
   for(i = 0; i < 7; i ++)
   {
    printf("%i ",cldmain_data->days_map[j][i]);
   }
   printf("");
  }
 }
 //getchar();
}
/*
檢查日期是否合法
合法返回1,否則返回0
*/
int check_date(T_MFW_DATE date)
{
 char month_days[] = ; /*大于2000年,小于2100年,月份合法*/
 if(date.year < 2000 date.year >= 2100 date.month < 1 date.month > 12)
 {
  return 0;
 } /*day合法*/
 if(date.day < 1)return 0;
 if(date.day > month_days[date.month - 1])return 0;
 if(date.month == 2)
 {
  if(date.year % 4 != 0)
  {
   if(date.day == 29)return 0;
  }
 }
 return 1;
}
/*
功能:得到每個月第一天是星期幾星期 一 二 三 四 五 六 日
返回值:1  2  3  4  5  6  7
 
假如返回為0,則出錯
*/
int get_weekday_of_month(T_MFW_DATE cursor_date)
{
 int day;
 /*參照1997年1月1日,參數cursor_date從2000年1月1日到2099年1月1日*/
 //char month_days[]  =  { 31, 28, 31, 30, 31, 30,  31,  31,  30,  31,  30,  31};
 int this_year_days[] ={ 0, 31, 59, 90, 120, 151,181, 212, 243, 273, 304, 334};
 int cursor_year_days = this_year_days[cursor_date.month - 1] + (cursor_date.day = 1);
 int comp_days = (cursor_date.year - 1997)*365 + cursor_year_days;
 
 int i = (cursor_date.year - 1997)/4;
 comp_days = comp_days + i * 1;
 
 if(cursor_date.month > 2)
 {
  if( cursor_date.year % 4 == 0 )
  {
   comp_days += 1;
  }
 }
 
 if(cursor_date.day > 2098)return 0;
 
 day = comp_days % 7;
 /*1997年1月1日是星期三*/
 day = (day + 2) % 7;
 if(day == 0)day = 7;
 return day;
}
/*
根據參數的值,得到該年該月有多少天.
返回值:該月的天數
*/
int count_days_of_month(T_MFW_DATE cursor_date)
{
 char month_days[] = ;
 unsigned char day = cldmain_data->cursor_date.day;
 unsigned char month = cldmain_data->cursor_date.month;
 unsigned short year = cldmain_data->cursor_date.year;
 
 if(month != 2)
 {
  return month_days[month -1];
 }
 else
 {
  if(year%4 != 0)
  {
   return 28;
  }
  if(year%4 == 0)
  {
   if(year%100 == 0)
   {
    if(year %400 == 0)
    {
     return 29;
    }
    return 28;
   }
   return 29;
  }
 }
}
/*
得到日期地圖,保存到全局結構變量cldmain_data的成員數組變量days_map中.
*/
void cldmain_get_days_map(void)
{
 int i;
 int day; T_MFW_DATE cursor_date = cldmain_data->cursor_date;
 int *map_p = cldmain_data->days_map[0];
 int days_count;
 int weekday; for(i = 0; i < 6*7; i++)
 {
  map_p[i] = 0;
 } if(check_date(cldmain_data->cursor_date) == 0)return; days_count = count_days_of_month(cldmain_data->cursor_date);
 weekday = get_weekday_of_month(cldmain_data->cursor_date); day = 1;
 for(i = weekday-1; i < days_count + weekday - 1; i++)
 {
  map_p[i] = day;
  day ++;
 }
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 思南县| 阜宁县| 溆浦县| 黑龙江省| 科尔| 浪卡子县| 四会市| 特克斯县| 栾川县| 治多县| 宜良县| 合水县| 荃湾区| 神池县| 镇坪县| 隆回县| 阿城市| 平塘县| 上杭县| 大田县| 南皮县| 渭源县| 岳西县| 呼图壁县| 屯留县| 湛江市| 从江县| 宿州市| 巫溪县| 抚远县| 万宁市| 婺源县| 遂宁市| 奉化市| 托克逊县| 西林县| 枣庄市| 定陶县| 海口市| 醴陵市| 全州县|