#include <stdio.h>
struct st_schedule {
int date;
char memo[128];
struct st_schedule* next;
};
void insertSchedule(struct st_schedule* prev, int date, char* memo){
struct st_schedule* newSch;
newSch = (struct st_schedule*)malloc(sizeof(struct st_schedule));
newSch->date = date;
strcpy(newSch->memo, memo);
newSch->next = prev->next;
prev->next = newSch;
}
void printSchedule(struct st_schedule* sch) {
for(; sch!=NULL; sch=sch->next) {
printf("%d: %s\n", sch->date, sch->memo);
}
}
void findSchedule(struct st_schedule* sch, int date) {
/* ここに書き足す。*/
}
void insertVacation(struct st_schedule* sch) {
/* ここに書き足す。*/
}
int main() {
struct st_schedule dummy = {0, "", (struct st_schedule *)NULL};
int date;
char buf[256], memo[128];
struct st_schedule *cur=&dummy, *prev;
/* いちいちキーボードから入力するのが面倒なときは次のコメントをはずす */
/*
struct st_schedule prog2[] = {
19991105, "第1回レポート提出", (struct st_schedule *)NULL,
19991126, "第2回レポート提出", (struct st_schedule *)NULL,
20000118, "第3回レポート提出", (struct st_schedule *)NULL,
20000202, "プログラミングII最終日", (struct st_schedule *)NULL,
20000223, "第4回レポート提出", (struct st_schedule *)NULL,
};
int i;
int n=sizeof(prog2)/sizeof(struct st_schedule);
dummy.next = prog2;
for (i=1; i<n; i++) {
prog2[i-1].next = &prog2[i];
}
cur = &prog2[n-1];
*/
while(1) { /* 入力 */
printf("「年月日 用件」を入力(例: 20000203 Setsubun)\n");
printf("空行で終了\n");
fgets(buf, 256, stdin);
if (sscanf(buf, "%d %s", &date, memo)<2) break;
insertSchedule(cur, date, memo);
cur=cur->next;
}
findSchedule(dummy.next, 20000223);
/* insertVacation(dummy.next); */
printSchedule(dummy.next);
}
|