首页 > 其他 > 详细

结构体指针作为函数参数

时间:2014-03-30 10:59:53      阅读:607      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1 #include <stdio.h>//原来有时候结构体变量不适宜在main函数外申明
 2  
 3 struct date_rec
 4 {
 5     int day;
 6     int month;
 7     int year;
 8 };
 9  
10 struct date_rec current_date;
11  
12 int days_of_month[][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
13 };
14  
15 int is_leap(int year)
16 {
17     return ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)));
18 }
19  
20 void input_date(struct date_rec *current_date)
21 {
22     printf("请输入当前日期(年 月 日):");
23     scanf("%d%d%d", &current_date->year, &current_date->month, &current_date->day);
24 }
25  
26 void increment_date(struct date_rec *current_date)
27 {
28     current_date->day++;
29     if (current_date->day > days_of_month[is_leap(current_date->year)][current_date->month])
30     {
31         current_date->day = current_date->day - days_of_month[is_leap(current_date->year)][current_date->month]
32                             ;
33         current_date->month++;
34         if (current_date->month > 12)
35         {
36             current_date->year++;
37             current_date->month = current_date->month - 12;
38         }
39     }
40 }
41  
42 void output_date(struct date_rec *current_date)
43 {
44     printf("当前日期:%d年%d月%d日!", current_date->year,
45            current_date->month, current_date->day);
46 }
47  
48 int main()
49 {
50     input_date(&current_date);
51     increment_date(&current_date);
52     output_date(&current_date);
53  
54     return 0;
55 }
bubuko.com,布布扣

结构体指针作为函数参数,布布扣,bubuko.com

结构体指针作为函数参数

原文:http://www.cnblogs.com/xzenith/p/3633132.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!