[英]Tabbing a Calendar console application using C
我正在使用ANSI C在控制台應用程序中以傳統格式實現一個簡單的年度日歷。必須將日歷制表符以顯示3 x 4個月的格式。 到現在為止,我設法將所有月份都顯示在下面,如下面的代碼所示。 任何幫助我該如何解決制表符部分? 我嘗試根據列將month []分成3個,例如Jan,April,April和July將是第一列,然后逐列工作,但是我不知道這是否是最好的選擇。 ..有什么幫助嗎?
#include<stdio.h>
int main()
{
int d,y,no_lp,n,i=1,j,month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("Enter year:");
scanf("%d", &y);
if (y%4==0)
{month[2]=29;}
no_lp= (27 + (42/5) + (y-1) + ((y-1)/4) - ((y-1)/100) + ((y-1)/400) + 1);
d= no_lp%7;
n=d;
for(j=1;j<=12;j++)
{
printf("\n\n %s",monthname[j]);
//printf ("\n\n%d",j);
printf("\n Su Mo Tu We Th Fr Sa\n");
while(d--!=0)
printf(" "); //spaces for empty days
while(i<=month[j])
{
if(i<10)
{printf(" %d ",i++);} //formating for dates with 2 digits
else{printf("%d ",i++);}//formatting for dates with 1 digit
n++;
if(n==7) //if 7 is reached start new line
{
n=0;
printf("\n");
}
}
d=n;
i=1; //n will be the 1st day of next month
}
return(0);
}
您可以更換
if(i<10)
{printf(" %d ",i++);} //formating for dates with 2 digits
else{printf("%d ",i++);}//formatting for dates with 1 digit
與
printf("%2d ",i++);
為了打印3 * 4,請勿即時打印
存儲這些值
char out[12][6][24];
| | |
n months <- | -> string containing week in calendar (e.g 10 11 12 13 14 15 17)
V
Max weeks in a month
並打印
week 1 month 1 , week 1 month 2 , week 1 month 3
week 2 month 1 , week 2 month 2 , week 2 month 3
week 3 month 1 , week 3 month 2 , week 3 month 3
...
week 1 month 4 , week 1 month 5 , week 1 month 6
week 2 month 4 , week 2 month 5 , week 2 month 6
week 3 month 4 , week 3 month 5 , week 3 month 6
...
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.