user-0 提问: 用C语言设计一个年历系统。。。求代码

回复:
user: user-1
content: 引用 3 楼 u013682489 的回复:我不会c++的，能改成c语言吗？  改了下，变量定义没有完全按照C语言的语法规则来。 你把文件命名为*.cpp后缀的即可。不要命名成*.c的   //日历C语言版本   作者QQ 93506222 于2014.2.17 #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <time.h>  //是否闰年 #define IS_LEAP_YEAR(iYear) (((iYear) % 100 == 0) ? ((iYear) % 400 == 0) : ((iYear) % 4 == 0))  int Calendar(int iYear, int iMonth);  void main() { 	//获取今天的日期 	struct tm *today; 	time_t ltime; 	time(<ime); 	today = localtime(<ime);  //	printf("%d-%02d-%02d %02d:%02d:%02d\n星期%d 当年第%d天\n",  //		today->tm_year + 1900, today->tm_mon + 1, today->tm_mday,  //		today->tm_hour, today->tm_min, today->tm_sec, today->tm_wday, today->tm_yday);  	int iYear = today->tm_year + 1900; 	int iMonth = today->tm_mon + 1;  	do { 		system("cls");  		int ch = Calendar(iYear, iMonth); 		if (ch == 27) break;  		switch (ch) 		{ 		case 75:	//<-- 			iYear--; 			break; 		case 77:	//--> 			iYear++; 			break; 		case 80:	//下箭头 			iMonth++; 			if (iMonth > 12) 			{ 				iYear++; 				iMonth = 1; 			} 			break; 		case 72:	//上箭头 			iMonth--; 			if (iMonth < 1) 			{ 				iYear--; 				iMonth = 12; 			} 			break; 		case 71:	//Home 			iYear = today->tm_year + 1900; 			iMonth = today->tm_mon + 1; 			break; 		} 	} while (1); }  //显示给定年月的日历 //返回值为获取的用户按键, 以确定下一步的操作 int Calendar(int iYear, int iMonth) { 	int i, j, iDays;  	//初始化数组w的值为1至31 	int w[31]; 	for (i = 0; i < 31; i++) w[i] = i+1; 	 	//获取本月天数于iDays中 	switch (iMonth) 	{ 	case 1: case 3: case 5: case 7: case 8: case 10: case 12: 		iDays = 31; 		break; 	case 4: case 6: case 9: case 11: 		iDays = 30; 		break; 	case 2: 		iDays = IS_LEAP_YEAR(iYear) ? 29 : 28; 		break; 	} 	 	//显示 日历头 	printf("\n    %d年%d月 日历\n\n", iYear, iMonth); 	printf(" 日 一 二 三 四 五 六\n"); 	printf("----------------------\n"); 	  	//获取参数指定年月的第一天是周几。保存在firstday.tm_wday中 	struct tm firstday = {0}; 	firstday.tm_year = iYear - 1900; 	firstday.tm_mon = iMonth - 1; 	firstday.tm_mday = 1;  	time_t ltime; 	ltime = mktime(&firstday);  	firstday = *localtime(<ime);  	//处理1号前的留空 	j = firstday.tm_wday;	//周几 	for (i = 0; i < j; i++) 	{ 		printf("   ");	//3个空格 	} 	 	//显示日历正文 	for (i = 0; i < iDays; i++) 	{ 		printf("%3d", w[i]); 		if (++j == 7) 		{ 			printf("\n");//逢七换行 			j = 0; 		} 	} 	if (j != 0) printf("\n");   	//获取今天日期 	time(<ime); 	struct tm today = *localtime(<ime);  	//显示 日历尾 	printf("----------------------\n"); 	printf("今天是: %d年%d月%d日\n\n", today.tm_year + 1900, today.tm_mon + 1, today.tm_mday);  	printf("←: 上一年  →: 下一年\n"); 	printf("↑: 上一月  ↓: 下一月\n\n"); 	printf("Home: 今天  Esc: 退出\n");  	//获取用户按键 (不用按回车立即返回) 	fflush(stdin); 	clearerr(stdin);  	int c = getch(); 	if (c == 0xe0 || c == 0) c = getch();  	return c; }

user: user-2
content: 《C语言课程设计案例精编》里有，当当网。

user: user-0
content: 我需要的是c语言

user: user-3
content: 下载链接： https://www.kernel.org/pub/linux/utils/util-linux/v2.18/

user: user-3
content: cal 20                                 20         January               February                 March Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa     1  2  3  4  5  6                1  2  3                   1  2  7  8  9 10 11 12 13    4  5  6  7  8  9 10    3  4  5  6  7  8  9 14 15 16 17 18 19 20   11 12 13 14 15 16 17   10 11 12 13 14 15 16 21 22 23 24 25 26 27   18 19 20 21 22 23 24   17 18 19 20 21 22 23 28 29 30 31            25 26 27 28 29         24 25 26 27 28 29 30                                               31         April                   May                   June Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa     1  2  3  4  5  6             1  2  3  4                      1  7  8  9 10 11 12 13    5  6  7  8  9 10 11    2  3  4  5  6  7  8 14 15 16 17 18 19 20   12 13 14 15 16 17 18    9 10 11 12 13 14 15 21 22 23 24 25 26 27   19 20 21 22 23 24 25   16 17 18 19 20 21 22 28 29 30               26 27 28 29 30 31      23 24 25 26 27 28 29                                               30         July                  August                September Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa     1  2  3  4  5  6                1  2  3    1  2  3  4  5  6  7  7  8  9 10 11 12 13    4  5  6  7  8  9 10    8  9 10 11 12 13 14 14 15 16 17 18 19 20   11 12 13 14 15 16 17   15 16 17 18 19 20 21 21 22 23 24 25 26 27   18 19 20 21 22 23 24   22 23 24 25 26 27 28 28 29 30 31            25 26 27 28 29 30 31   29 30         October               November               December Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa        1  2  3  4  5                   1  2    1  2  3  4  5  6  7  6  7  8  9 10 11 12    3  4  5  6  7  8  9    8  9 10 11 12 13 14 13 14 15 16 17 18 19   10 11 12 13 14 15 16   15 16 17 18 19 20 21 20 21 22 23 24 25 26   17 18 19 20 21 22 23   22 23 24 25 26 27 28 27 28 29 30 31         24 25 26 27 28 29 30   29 30 31  linux有cal这个工具的， 属于这个包util-linux-ng

user: user-0
content: 我不会c++的，能改成c语言吗？

user: user-4
content: 仅供参考#include <stdio.h> #include <string.h> #include <time.h> struct tm st; time_t tt; char timstr[40]; char tmpbuf[128]; char c; int t; int AP() {     if ('P'==c || 'p'==c) {st.tm_hour+=12;return 1;}     if ('A'==c || 'a'==c)                 return 1;                                           return 0; } int dtparse() {     if (7==sscanf(timstr,"%d/%d/%4d %d:%d:%d %c",&st.tm_mday,&st.tm_mon ,&st.tm_year,&st.tm_hour,&st.tm_min,&st.tm_sec,&c)) if (AP()) goto STEP2;     if (6==sscanf(timstr,"%d/%d/%4d %d:%d%c"    ,&st.tm_mday,&st.tm_mon ,&st.tm_year,&st.tm_hour,&st.tm_min           ,&c)) if (AP()) goto STEP1;     if (6==sscanf(timstr,"%4d/%d/%d %d:%d %c"   ,&st.tm_year,&st.tm_mon ,&st.tm_mday,&st.tm_hour,&st.tm_min           ,&c)) if (AP()) goto STEP1;     if (5==sscanf(timstr,"%d.%d.%4d %d:%d"      ,&st.tm_mon ,&st.tm_mday,&st.tm_year,&st.tm_hour,&st.tm_min              ))           goto STEP1;     if (6==sscanf(timstr,"%4d-%d-%d %d:%d:%d"   ,&st.tm_year,&st.tm_mon ,&st.tm_mday,&st.tm_hour,&st.tm_min,&st.tm_sec   ))           goto STEP2; STEP1:     st.tm_sec=0; STEP2:     st.tm_year-=1900;     if (st.tm_mon>12) {t=st.tm_mon;st.tm_mon=st.tm_mday;st.tm_mday=t;}     st.tm_mon-=1;     tt=mktime(&st);     if (-1!=tt) {         strftime(tmpbuf,128,"%Y-%m-%d %H:%M:%S",localtime(&tt));         return 1;     } else {         printf("[%s] is Invalid time string!\n",timstr);         return 0;     } } int main() {     strcpy(timstr,"10.01.2012 15:43"        );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);     strcpy(timstr,"8/11/2006 11:10AM"       );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);     strcpy(timstr,"2006/10/31 04:50 PM"     );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);     strcpy(timstr,"1/6/2010 5:20:12 PM"     );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);     strcpy(timstr,"13/12/2012 11:16:17 a.m.");if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);     strcpy(timstr,"2013-06-08 09:56:59"     );if (dtparse()) printf("[%s] is [%s]\n",timstr,tmpbuf);     return 0; } //[10.01.2012 15:43] is [2012-10-01 15:43:00] //[8/11/2006 11:10AM] is [2006-11-08 11:10:00] //[2006/10/31 04:50 PM] is [2006-10-31 16:50:00] //[1/6/2010 5:20:12 PM] is [2010-06-01 17:20:12] //[13/12/2012 11:16:17 a.m.] is [2012-12-13 11:16:17] //[2013-06-08 09:56:59] is [2013-06-08 09:56:59] //

user: user-1
content: 这是C++版本的，将其中的C++语法改成C语言的即可。  //日历   作者QQ 93506222 于2012.9.22 #include <iostream> using namespace std;  #include <iomanip> #include <windows.h> #include <conio.h>  //是否闰年 #define IS_LEAP_YEAR(iYear) (((iYear) % 100 == 0) ? ((iYear) % 400 == 0) : ((iYear) % 4 == 0))  int Calendar(int iYear, int iMonth);  void main() { 	//获取今天的日期 	SYSTEMTIME tm; 	::GetLocalTime(&tm); 	int iYear = tm.wYear; 	int iMonth = tm.wMonth;  	do { 		system("cls");  		int ch = Calendar(iYear, iMonth); 		if (ch == 27) break;  		switch (ch) 		{ 		case 75:	//<-- 			iYear--; 			break; 		case 77:	//--> 			iYear++; 			break; 		case 80:	//下箭头 			iMonth++; 			if (iMonth > 12) 			{ 				iYear++; 				iMonth = 1; 			} 			break; 		case 72:	//上箭头 			iMonth--; 			if (iMonth < 1) 			{ 				iYear--; 				iMonth = 12; 			} 			break; 		case 71:	//Home 			iYear = tm.wYear; 			iMonth = tm.wMonth; 			break; 		} 	} while (1); }  //显示给定年月的日历 //返回值为获取的用户按键, 以确定下一步的操作 int Calendar(int iYear, int iMonth) { 	int i, j, iDays;  	//初始化数组w的值为1至31 	int w[31]; 	for (i = 0; i < 31; i++) w[i] = i+1; 	 	//获取今天的日期 	SYSTEMTIME tmToday; 	::GetLocalTime(&tmToday);  	//获取参数指定年月的第一天是周几。保存在tm1.wDayOfWeek中 	SYSTEMTIME tm1 = tmToday; 	tm1.wYear = iYear; 	tm1.wMonth = iMonth; 	tm1.wDay = 1; 	::SetLocalTime(&tm1); 	::GetLocalTime(&tm1);  	::SetLocalTime(&tmToday);  	//获取本月天数于iDays中 	switch (tm1.wMonth) 	{ 	case 1: case 3: case 5: case 7: case 8: case 10: case 12: 		iDays = 31; 		break; 	case 4: case 6: case 9: case 11: 		iDays = 30; 		break; 	case 2: 		iDays = IS_LEAP_YEAR(tm1.wYear) ? 29 : 28; 		break; 	} 	 	//显示 日历头 	cout << endl << "    " << tm1.wYear << "年" << tm1.wMonth << "月 日历" << endl << endl; 	cout << " 日 一 二 三 四 五 六" << endl; 	cout << "----------------------" << endl; 	 	//处理1号前的留空 	j = tm1.wDayOfWeek; 	for (i = 0; i < j; i++) 	{ 		cout << "   ";	//3个空格 	} 	 	//显示日历正文 	for (i = 0; i < iDays; i++) 	{ 		cout << setw(3) << w[i]; 		if (++j == 7) 		{ 			cout << endl;	//逢七换行 			j = 0; 		} 	} 	if (j != 0) cout << endl;  	//显示 日历尾 	cout << "----------------------" << endl; 	cout << "今天是: " << tmToday.wYear << "年" << tmToday.wMonth << "月" << tmToday.wDay << "日" << endl << endl ;  	cout << "←: 上一年  →: 下一年" << endl; 	cout << "↑: 上一月  ↓: 下一月" << endl << endl; 	cout << "Home: 今天  Esc: 退出" << endl;  	//获取用户按键 (不用按回车立即返回) 	fflush(stdin); 	clearerr(stdin);  	int c = getch(); 	if (c == 0xe0 || c == 0) c = getch();  	return c; }