标题:刚学C,求帮忙看个程序,看看哪里错了为什么运行错误/*计算下一秒时间*/
只看楼主
corey_whu
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-6-13
结帖率:100%
已结贴  问题点数:10 回复次数:6 
刚学C,求帮忙看个程序,看看哪里错了为什么运行错误/*计算下一秒时间*/
/*计算下一秒时间*/
#include<stdio.h>
#include<stdlib.h>

struct time{
       int hour;
       int minute;
       int second;
       };

struct time readTime();
struct time nextTime(struct time t);

int main()
{
    struct time nowTime,next_time;

    nowTime = readTime();
    next_time = nextTime(nowTime);

    printf("nowTime = %d:%d:%d\n",nowTime.hour,nowTime.minute,nowTime.second);
    printf("next_time = %d:%d:%d\n",next_time.hour,next_time.minute,next_time.second);

    system("PAUSE");
    return 0;
}
struct time readTime()
{
    struct time t;
    int error;

    do{
          error = 0;
          scanf("%d:%d:%d",t.hour,t.minute,t.second);

          if(t.hour<0||t.hour>23)
             {
             printf("小时数据错误:0~23!\n");
             error = 1;
             }
          if(t.minute<0||t.minute>59)
          {
              printf("分钟数据错误:0~59!\n");
              error = 1;
          }
          if(t.second<0||t.second>59)
          {
              printf("秒钟数据错误:0~59!\n");
              error = 1;
          }
          if(error)
              printf("重新输入!\n");
          }while(error);
         

          return t;
}

struct time nextTime(struct time t)
{
    t.second++;
    if(t.second>59)
    {
        t.second = 0;
        t.minute++;
        if(t.minute>59)
        {
            t.minute = 0;
            t.hour++;
            if(t.hour>23)
              t.hour = 0;
        }
    }

    return t;
搜索更多相关主题的帖子: 计算 时间 include system minute 
2012-07-02 23:01
corey_whu
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-6-13
得分:0 
在线等一小时。。。
2012-07-02 23:15
随风飘荡
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:208
专家分:598
注 册:2011-9-9
得分:6 
。。。scanf啊scanf,果然我就是个眼科大夫,少了取址符啊
2012-07-04 02:06
chinaflag
Rank: 2
来 自:福建泉州
等 级:论坛游民
帖 子:46
专家分:83
注 册:2012-4-1
得分:4 
楼上正解,scanf("%d:%d:%d",&t.hour,&t.minute,&t.second);这样应该就可以了
2012-07-04 10:24
lanxinyuemo
Rank: 2
等 级:论坛游民
帖 子:24
专家分:29
注 册:2010-3-9
得分:0 
最好那个函数没有}?
2012-07-04 12:30
ytiantian_ha
Rank: 2
等 级:论坛游民
帖 子:29
专家分:19
注 册:2012-7-1
得分:0 
少一个括号
2012-07-04 13:29
corey_whu
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-6-13
得分:0 
回复 3楼 随风飘荡
3Q啦。。。汗。。低级错误。。
2012-07-06 21:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-372686-1-1.html




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

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