惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
Arctic Wolf
博客园 - 聂微东
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
小众软件
小众软件
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
L
LangChain Blog
A
About on SuperTechFans
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
T
The Blog of Author Tim Ferriss
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
Know Your Adversary
Know Your Adversary
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Palo Alto Networks Blog
Scott Helme
Scott Helme
S
Secure Thoughts
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
Attack and Defense Labs
Attack and Defense Labs
P
Privacy & Cybersecurity Law Blog
O
OpenAI News
H
Heimdal Security Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Help Net Security
Help Net Security
C
Cyber Attacks, Cyber Crime and Cyber Security
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
G
Google Developers Blog
博客园 - Franky
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
Kaspersky official blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Tor Project blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tenable Blog
Google Online Security Blog
Google Online Security Blog
PCI Perspectives
PCI Perspectives

博客园 - 撬棍

【.Net】2、8、16进制转换 【.Net】执行CMD命令 【.Net】获取随机数函数 【.Net】注册程序开机启动 【.Net】把窗体“钉”到桌面上 【.Net】多语言查看MSDN 【.Net】 显示星期字符串 【.Net】 判断时间字符串正确性 【.Net】 实现窗口拖动 【.Net】 Winform 单例运行实例 [C++]函数返回值 [C++]数组参数 [C++]const的指针使用 [C++]指针类型出参 [VBA]Excel输出utf-8编码格式文件 使用WideCharToMultiByte 【C++】split [VB6.0]让程序在任务列表和资源管理器“隐身” [InstallShield]FindAllFiles与SetFileInfo配合实现文件加多文件属性设置 [VB]修改注册表让程序开机自动运行 - 撬棍 - 博客园
[C语言学习]之打印万年历 - 撬棍 - 博客园
撬棍 · 2010-12-10 · via 博客园 - 撬棍

#include "stdio.h"

//functions define
void outputcalendar(void);
void outputtitle(int);
void outputbody(int *, int maxday);
int *getweek(int, int, int);

//variables and constants
const char CON_STR4SPACE[5]  = "    ";
const char CON_STR1SPACE[2] = " ";
const int CON_DAYCOUNTS31 = 31;
const int CON_DAYCOUNTS30 = 30;
int daycountsofFeb;

//function main
int main()
{
  outputcalendar();
    return 0;
}


//functions
void outputcalendar(void)
{
 while(true)
 {
  int year,month;
  int *weekp;

  printf("please input year:");
  scanf("%d",&year);

  if(year < 0 || year > 9999)
  {
   printf("the input year must between 0 to 9999!\n",year);
   continue;
  }

  //get week the first day of year
  weekp = getweek(year,1,1);

  //get the days of Feb
  daycountsofFeb = 28;
  if(year%4==0 && year%100!=0 || year%400==0)
   daycountsofFeb++;

  printf("[Calendar Of Year %d]\n",year);

  for(month=1; month<13; ++month)
  {
   outputtitle(month);

   switch (month)
   {
    case 1:
     /*no break;*/
    case 3:
     /*no break;*/
    case 5:
     /*no break;*/
    case 7:
     /*no break;*/
    case 8:
     /*no break;*/
    case 10:
     /*no break;*/
    case 12:
     outputbody(weekp, 31);
     break;
    case 2:
     outputbody(weekp, daycountsofFeb);
     break;
    case 4:
     /*no break;*/
    case 6:
     /*no break;*/
    case 9:
     /*no break;*/
    case 11:
     outputbody(weekp, 30);
     break;
   }//end of switch
   printf("\n");
  }//end of For
  printf("\n");
 }//end of while
}//end of function

void outputtitle(int month)
{
 char *monthname[4] ;
 switch (month)
 {
  case 1:
   *monthname = "Jan";
   break;
  case 2:
   *monthname = "Feb";
   break;
  case 3:
   *monthname = "Mar";
   break;
  case 4:
   *monthname = "Apr";
   break;
  case 5:
   *monthname = "May";
   break;
  case 6:
   *monthname = "Jun";
   break;
  case 7:
   *monthname = "Jul";
   break;
  case 8:
   *monthname = "Aug";
   break;
  case 9:
   *monthname = "Sep";
   break;
  case 10:
   *monthname = "Oct";
   break;
  case 11:
   *monthname = "Nov";
   break;
  case 12:
   *monthname = "Dec";
   break;
 }//end of switch

 printf("------------%s------------\n",*monthname);
 printf("  S- -1- -2- -3- -4- -5- -6\n");
}
void outputbody(int *m, int maxday)
{
 int i,c = 0;
 for(i=1; i<=*m; i++)
 {
  c++;
  printf(CON_STR4SPACE);
 }
 for(i=1; i<=maxday; i++)
 {
  c++;
  if(c%7-1==0 && c!=1)
   printf("\n");
  if(i<10)
   printf(CON_STR1SPACE);
  printf(" %d ",i);
  *m = ++(*m)%7;
 }
}

int *getweek(int year, int month, int day)
{
 static int week;
 int *p;
 int lastyear, i, days = 0;
 int mont[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
 //char wek[][9] = { {'S','u','n','d','a','y'},
 //    {'M','o','n','d','a','y'},
 //    {'T','u','e','s','d','a','y'},
 //    {'W','e','d','n','s','d','a','y'},
 //    {'T','h','u','r','s','d','a','y'},
 //    {'F','r','i','d','a','y'},
 //    {'S','a','t','u','r','d','a','y'}
 //    };

 if (year%4==0||year%100==0||year%400==0)
  mont[2] += 1;

 if ((year < 0 || year > 9999) ||
  (month < 1 || month > 12) || 
  (day > mont[month] || day < 1)
  )
 {
  //error date return -1
  week = -1;
  p = &week;
  return p;
 }

 for (i=1;i<month;i++)
  days += mont[i];

 days += day;

 lastyear = year - 1;
 days += lastyear*365 + (int)(lastyear/4) - (int)(lastyear/100) + (int)(lastyear/400);
 week = days % 7;

 p = &week;
 return p;
}