求c语言大神指点 gettime函数的使用 ,用来编辑个时钟

在网上找到这个答案
#include <stdio.h>
#include <dos.h>

int main(void)
{
struct time t;

gettime(&t);
printf("The current time is: %2d:%02d:%02d.%02d\n",
t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
return 0;
}
可我复制进去怎么出现这种错误 error: aggregate `time t' has incomplete type and cannot be defined还有 error: `gettime' was not declared in this scope

第1个回答  推荐于2016-11-15
你的代码没有错,在DOS的C下没有问题。但DOS的有些时间函数在C++编译器下已经无效了。可尝试用下面的——
#include "stdio.h"
#include "time.h"
#include <DOS.H>
void main(void){
struct tm *pt;
time_t t;
t=time(NULL);
pt=localtime(&t);
printf("The current time is: %2d:%02d:%02d\n",
pt->tm_hour, pt->tm_min, pt->tm_sec);
}
但tm结构没有ms级变量。追问

怎么不断刷新时间

追答

把这段代码写在一个程序的大循环里才行。

本回答被提问者和网友采纳
第2个回答  2014-11-03
#include<stdio.h> 
#include<time.h>

int main(void) 

   tm t; 

   _getsystime(&t); 
   printf("The current time is: %2d:%02d:%02d\n", t.tm_hour, t.tm_min, t.tm_sec); 
   return 0; 
}

追问

tm是时间类型么

追答

这是一个系统定义好的结构体,专门用来保存时间的,在time.h中声明,直接使用即可。

struct tm {
        int tm_sec;     /* seconds after the minute - [0,59] */
        int tm_min;     /* minutes after the hour - [0,59] */
        int tm_hour;    /* hours since midnight - [0,23] */
        int tm_mday;    /* day of the month - [1,31] */
        int tm_mon;     /* months since January - [0,11] */
        int tm_year;    /* years since 1900 */
        int tm_wday;    /* days since Sunday - [0,6] */
        int tm_yday;    /* days since January 1 - [0,365] */
        int tm_isdst;   /* daylight savings time flag */
        };

第3个回答  2014-11-03
gettime C语言里没有这函数!追问

好的我试试

追答

别试了 C语言里没这函数 要用就用gettimeofday或time函数

追问

,,,,我说怎么不行

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网