typedef 定义结构体

/* 1、先搭建程序的框架
   2、(1)结构体变量的运用,用typedef可以如此命名结构体变量 DATE today,DATE currentDay,这几个变量名可以直接放到函数里当参量,当函数用到结构体里面的元素时,在用点运算符替换
      (2)运用了2个函数int countDay()和int runYear()


*/

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
//定义日期结构体


/*不用typedef时,结构体变量命名的一般格式
struct date                        //date不是变量的名字,是数据类型名,和int等属于平级
{ 
......
}date1,date2,date3;
struct date date4 ,date5;       //声明date4和date5是结构体变量


*/

typedef struct date               //date不是变量的名字,是数据类型名,和int等属于平级
{
	int year;
	int month;
	int day;
}DATE;                            /*用typedef,DATE就是结构体的别名*/                                                
		   

int countDay(DATE);
int runYear(years);

void main()
{
	DATE today;
	int totalDay;
	int result;

	printf("please input 指定日期 包括年,月,日 如:1999 1 31\n");
	scanf("%d%d%d", &today.year, &today.month, &today.day);

	totalDay = countDay(today);
	result = totalDay % 5;

	if (result > 0 && result < 4)
		printf("今天打鱼");
	else
		printf("今天晒网");
}

int runYear(int(year))
{
	if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
		return 1;
	else
		return 0;
}


int countDay(DATE currentDay)
{
	int perMonth[13] = { 0,31,28,31,30,31,30,31,31,30,31,30 };

	int totalDay = 0, year, i;
	for (year = 1990; year < currentDay.year; year++)
	{
		if (runYear(year))
			totalDay = totalDay + 366;
		else
			totalDay = totalDay + 365;
	}

	if (runYear(currentDay.year))
		perMonth[2] += 1;
	for (i = 0; i < currentDay.month; i++)
		totalDay += perMonth[i];
	totalDay += currentDay.day;
	return totalDay;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值