| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 496 人关注过本帖
标题:关于结构的C程序,菜鸟求助
取消只看楼主 加入收藏
ouyangjapana
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-10-21
收藏
 问题点数:0 回复次数:1 
关于结构的C程序,菜鸟求助


#include "stdio.h"
struct date
{
int month;
int day;
int year;
};
struct time
{
int hour;
int minute;
int seconds;
};
struct dateAndTime
{
struct date sdate;
struct time stime;
};
main()
{
struct dateAndTime ClockKeeper(struct dateAndTime numberDate);
struct dateAndTime numberNow, turnNow;
printf("Enter time and date is:(hh:mm:ss mm/dd/yy)");
scanf("%d:%d:%d %d/%d/%d",&numberNow.stime.hour,&numberNow.stime.minute,&numberNow.stime.seconds,
&numberNow.sdate.month,&numberNow.sdate.day,&numberNow.sdate.year);
turnNow = ClockKeeper(numberNow);
printf("Right now time and date : %.2d:%.2d:%.2d %d/%d/%.2d\n",turnNow.stime.hour,
turnNow.stime.minute,turnNow.stime.seconds,turnNow.sdate.month,turnNow.sdate.day,
turnNow.sdate.year % 100);

}
struct dateAndTime ClockKeeper (struct dateAndTime numberDate)
{
struct dateAndTime dateUpdate(struct dateAndTime n);
++numberDate.stime.seconds;
if(numberDate.stime.seconds == 60){
numberDate.stime.seconds = 0;
++numberDate.stime.minute;
if(numberDate.stime.minute == 60){
numberDate.stime.minute = 0;
++numberDate.stime.hour;
if(numberDate.stime.hour == 24){
numberDate.stime.hour = 0;
struct dateAndTime dateUpdate(struct dateAndTime numberDate);
}
}
}
return numberDate;

}
struct dateAndTime dateUpdate(struct dateAndTime n)
{

const int dayperMonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};
if(n.sdate.day == dayperMonth[n.sdate.month - 1]){
n.sdate.day = 0;
n.sdate.month++;
if(n.sdate.month == 12){
n.sdate.month = 0;
n.sdate.year++;
}
}
return n;
}

搜索更多相关主题的帖子: 结构 
2006-11-02 21:37
ouyangjapana
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-10-21
收藏
得分:0 

是关于我写的自定义函数struct dateAndTime dateUpdate(struct dateAndTime numberDate);编译的时候提示有错误,不知道错在那里,帮忙分析一下,谢谢

2006-11-03 21:09
快速回复:关于结构的C程序,菜鸟求助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015465 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved