#include<stdio.h>
#include<string.h>
struct schedule {
int year;
int month;
int day;
int hour;
char title[100];
struct schedule *next;
};
void update2years(struct schedule *target){
target->year = target->year + 2;
}
void printSchedule(struct schedule target){
printf("year:%04d, month:%02d, day:%02d, hour:%02d, title:%s\n", target.year, target.month, target.day, target.hour, target.title);
}
int main(void){
struct schedule exam1;
struct schedule exam2;
exam1.year = 2021;
exam1.month = 10;
exam1.day = 30;
exam1.hour = 10;
exam1.next = &exam2;
exam2.year = 2021;
exam2.month = 12;
exam2.day = 25;
exam2.hour = 23;
exam2.next = NULL;
// -1: 末尾\0のため
strncpy(exam1.title, "ハロウィン", sizeof(exam1.title)-1);
strncpy(exam2.title, "クリスマス", sizeof(exam1.title)-1);
printSchedule(exam1);
printSchedule(*exam1.next);
printSchedule(exam2);
update2years(&exam1);
update2years(&exam2);
printSchedule(exam1);
printSchedule(*exam1.next);
printSchedule(exam2);
return 0;
}
// 実行結果
year:2021, month:10, day:30, hour:10, title:ハロウィン
year:2021, month:12, day:25, hour:23, title:クリスマス
year:2021, month:12, day:25, hour:23, title:クリスマス
year:2023, month:10, day:30, hour:10, title:ハロウィン
year:2023, month:12, day:25, hour:23, title:クリスマス
year:2023, month:12, day:25, hour:23, title:クリスマス
参考