qt调用c语言函数库_Qt给C程序做界面的简单应用(笔记)

这篇博客介绍了如何利用Qt来调用C语言编写的函数库,以计算从生日到当前日期的总天数。通过定义一系列静态函数,包括判断闰年、获取某月天数、计算生日当年剩余天数、计算中间年份的总天数以及当前年份已过去天数,最后将这些函数整合到`sumBirth`函数中,实现所需功能。
摘要由CSDN通过智能技术生成

/*To calculate your days from birthday to

current time.*/

#include

#include

#include

static int is_LeapOrFract(const int year)/*Leap year of Fractional year*/

{

if((year%4==0&&year%100!=0)||year%400==0)

return

366;

else

return

365;

}

static int is_Month_day(const int month,const

int year)/*How many days of this

month*/

{

if(month<1||month>12)

{

printf("Wrong

number!\n");

exit(-1);

}

if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)

return

31;

else

if(month==2)

{

if(is_LeapOrFract(year)==366)

return

29;

else

return

28;

}

else

return

30;

}

static int first_part(const int

year,const int month,const int day)/*The

last days of birthyear*/

{

int

i,sum=0;

for(i=12;i>month;i--)

{

sum+=is_Month_day(i,year);

}

return

is_Month_day(month,year)-day+sum;

}

static int second_part(const int

year,const int nyear)/*The days of

the years between birthyear and this year*/

{

int

i,sum=0;

i=year+1;

for(;i

{

sum+=is_LeapOrFract(i);

}

return

sum;

}

static int third_part(const int

year,const int month,const int day)/*The

past days of this year*/

{

int

i,sum=0;

for(i=1;i

{

sum+=is_Month_day(i,year);

}

return

sum+day;

}

extern int sumBirth(const int year,const

int month,const int day)

{

time_t

now;

struct

tm *curtime;

int

nyear,nmonth,nday;

int

sum=0,sumfirst=0,sumsecond=0,sumthird=0;

time(&now);/*Get the

arguments of current time (year month and day)*/

curtime=localtime(&now);

nyear=curtime->tm_year+1900;

nmonth=curtime->tm_mon+1;

nday=curtime->tm_mday;

sumfirst=first_part(year,month,day);

sumsecond=second_part(year,nyear);

sumthird=third_part(nyear,nmonth,nday);

if(year==nyear)

sum=sumthird-third_part(year,month,day);

else

sum=sumfirst+sumsecond+sumthird;

return

sum;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值