본문 바로가기

컴퓨터/언어,프로그래밍

[C] 일정관리프로그램

#include <stdio.h>
#include <string.h>

int main(void)
{
       
char calendar[12*31*100][26];
       
char *pData;
       
char temp[100],gyear[100];
       
int i,j,week,year,month,day,th,count,lastday,tyear,mode,pos,tmonth;
       
int num[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
       
FILE *file;
       
for(i=0;i<26;i++)
                memset(calendar[i],
0,12*31*100);
        pData=calendar[
0];
       
while(1)
        {
                printf(
"──────────────2000~2025년 일정 관리───────────────\n");
                printf(
"\n                 [1]일정 쓰기 [2]일정 확인 [3]저장 [4]열기 [0]종료 :");
                gets(temp);
                sscanf(temp,
"%d",&mode);
               
if(mode==0)
                       
break;
               
switch(mode)
                {
               
case 1:
                        printf(
"YEAR: ");
                        gets(gyear);
                        sscanf(gyear,
"%d",&year);
                       
if(year>2025 || year<2000)
                        {
                                printf(
"다시 입력 하세요\n");
                               
break;
                        }
                        tyear=year;
                        pData=calendar[year-
2000];
                        printf(
"MONTH: ");
                        gets(temp);
                        sscanf(temp,
"%d",&month);
                        tmonth=month;
                       
if(tmonth>12 || tmonth<1)
                        {
                                printf(
"다시 입력 하세요\n");
                               
break;
                        }
                        lastday = num[tmonth -
1];
                       
if( tmonth == 2 && (!(tyear%4) && (tyear%100) || !(tyear%400)) )
                                lastday =
29;
                       
if (tmonth == 2 || tmonth == 1)
                        {
                                tyear--;
                                tmonth +=
12;
                        }
                        th = tyear /
100;
                        tyear = tyear %
100;
                        week = ((
21 * th / 4) + (5 * tyear / 4) + (26 * (tmonth + 1)) / 10) % 7;
                        printf(
"\n 일 월 화 수 목 금 토 \n");
                        count =
1;
                       
for (i = 0; i < 6 ; i++)
                        {
                               
for (j = 0; j < 7; j++)
                                {
                                       
if(i == 0 && j < week)
                                                printf(
"%3s"," ");
                                       
else
                                        {
                                                printf(
"%3d", count);
                                                count++;
                                        }
                                       
if (count > lastday)
                                               
break;
                                }
                                printf(
"\n");
                               
if (count > lastday)
                                       
break;
                        }
                        printf(
"\nDAY: ");
                        gets(temp);
                        sscanf(temp,
"%d",&day);
                       
if(day>lastday || day<1)
                        {
                                printf(
"다시 입력 하세요\n");
                               
break;
                        }
                        pos=month*day*
10;
                        pData=pData+pos;
                        printf(
"\n●일정을 쓰세요.\n");
                        printf(
"\n   %d%d%d일 :",year,month,day);
                        gets(temp);
                        strcpy(pData,temp);
                       
break;
               
case 2:
                        printf(
"YEAR: ");
                        gets(temp);
                        sscanf(temp,
"%d",&year);
                       
if(year>2025 || year<2000)
                        {
                                printf(
"다시 입력 하세요\n");
                               
break;
                        }
                        pData=calendar[year-
2000];
                        printf(
"MONTH: ");
                        gets(temp);
                        sscanf(temp,
"%d",&month);
                       
if(month>12 || month<1)
                        {
                                printf(
"다시 입력 하세요\n");
                               
break;
                        }
                        printf(
"DAY: ");
                        gets(temp);
                        sscanf(temp,
"%d",&day);
                       
if(day<1)
                        {
                                printf(
"다시 입력 하세요\n");
                               
break;
                        }
                        pos=month*day*
10;
                        pData=pData+pos;
                        printf(
"\n●일정 입니다.\n");
                        printf(
"\n   %d%d%d일 :%s\n",year,month,day,pData);
                       
break;
               
case 3:
                        file=fopen(
"test.db","wb");
                       
for(i=0;i<26;i++)
                                fwrite(calendar[i],
1,12*31*100,file);
                        fclose(file);
                       
break;
               
case 4:
                        file=fopen(
"test.db","rb");
                       
for(i=0;i<26;i++)
                                fread(calendar[i],
1,12*31*100,file);
                        fclose(file);
                        pData=calendar[
0];
                       
break;
               
default:
                        printf(
"다시 입력 하세요\n");
                       
break
;
                }
        }
}
제주삼다수, 2L,... 오뚜기 진라면 매운... 상하목장 유기농 흰... 남양 프렌치카페 카... 고려인삼유통 홍삼 ... 종근당건강 오메가3... 요이치 카링 유무선...