标题:时钟代码,执行后出现"undefined reference to 'gettime' ",求各位大神指点 ...
只看楼主
pxf
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2016-4-13
结帖率:80%
已结贴  问题点数:20 回复次数:3 
时钟代码,执行后出现"undefined reference to 'gettime' ",求各位大神指点
#include<stdio.h>
#include<math.h>
#include<dos.h>
#include<conio.h>
#include<windows.h>
#include<sys/time.h>
int main()
{
    struct time
    {
        unsigned char ti_min;
        unsigned char ti_hour;
        unsigned char ti_hund;
        unsigned char ti_sec;
    };
    struct time curtime;
    float th_hour,th_min,th_sec;
    do
    {
        printf("****************************************\n");
        printf("**This is a simple clock program      **\n");
        printf("**                                    **\n");
        printf("****************************************\n");
        printf("The currenr time is:\n");

        gettime(&curtime);
        if((float)curtime.ti_hour<=12)
        {
            printf("AM");
            if((float)curtime.ti_hour<10)
                printf("0");
            printf("%.0f:",(float)curtime.ti_hour);
        }
        else
        {
            printf("PM");
            if((float)curtime.ti_hour<10)
                printf("0");
            printf("%.0f:",(float)curtime.ti_hour);
        }
        if((float)curtime.ti_min<10)
            printf("0");
        printf("%.0f:",(float)curtime.ti_min);
        if((float)curtime.ti_sec<10)
            printf("0");
        printf("%.0f:",(float)curtime.ti_sec);
        Sleep(1000);
        system ("cls");
    }while (1);
}
搜索更多相关主题的帖子: undefined reference include simple 
2016-04-17 15:02
alice_usnet
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:18
帖 子:370
专家分:2020
注 册:2016-3-7
得分:20 
用localtime

未佩好剑,转身便已是江湖
2016-04-17 16:07
pxf
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2016-4-13
得分:0 
回复 2楼 alice_usnet
谢谢大神,可是时间输出不对,时间为16:33时,编译生成PM26:158:00,是不是算法不对
2016-04-17 16:35
alice_usnet
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:18
帖 子:370
专家分:2020
注 册:2016-3-7
得分:0 
回复 3楼 pxf
程序代码:
#include<stdio.h>
#include<time.h>
int main()
{
    time_t ntime;
    struct tm *now;
    time(&ntime);
    now=localtime(&ntime);
    printf("%4d-%02d-%02d %02d:%02d:%02d\n",1900+now->tm_year,now->tm_mon+1,now->tm_mday,now->tm_hour,now->tm_min,now->tm_sec);
}
收到的鲜花
  • pxf2016-05-07 14:52 送鲜花  3朵   附言:我很赞同

未佩好剑,转身便已是江湖
2016-04-17 17:11



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




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

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