网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > C/C++
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.贪婪算法---货箱装船.
.进程调度模拟程序.
.C++ 和 Delphi 的函数覆盖(Overr.
.Web中DataGrid绑定数据显示列可拖.
.修练8年C++面向对象程序设计之体.
.C++中extern “C”含义深层探索.
.C/C++中字符指针数组及指向指针的.
.骑士漫游和八皇后.
.qmail-local代码分析.
.Bjarne:为何析构函数默认不是vir.
.VC的若干实用小技巧(四).
.链表的c语言实现(八).
.C语言库函数(O类字母).
.Web应用程序开发技术.
.使用C++异常来取代exit()函数.
.C++中结构体的的慨念和使用方法.
.用C++程序删除文本文件中以“//”.
.如何获取打印机参数.
.用Visual C++在单文档界面中创建.
.Linux上搭建C/C++IDE.

用c写的一个日历文件

发表日期:2008-3-8


/*
该程序在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);   printf("year month:");
  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 %d month %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 ++;
 }
}

上一篇:用托管C++监视Windows事件日志 人气:771
下一篇:用C实现exp函数! 人气:893
浏览全部C/C++的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐