求C程序,Dev-C++可运行的,求大神

如题所述

#ifndef _DATE_TIME_H
#define _DTTE_TIME_H

#include<time.h>
int get_year(){
time_t t;
struct tm *l;
t = time(&t);
l = localtime(&t);
return (l->tm_year + 1900);}
int get_month(){
time_t t;
struct tm *l;
t = time(&t);
l = localtime(&t);
return (l->tm_mon+1);}
int get_day(){
time_t t;
struct tm *l;
t = time(&t);
l = localtime(&t);
return (l->tm_mday);}
int get_hour(){
time_t t;
struct tm *l;
t = time(&t);
l = localtime(&t);
return (l->tm_hour);}
int get_minuts(){
time_t t;
struct tm *l;
t = time(&t);
l = localtime(&t);
return (l->tm_min);}
int get_seconds(){
time_t t;
struct tm *l;
t = time(&t);
l = localtime(&t);
return (l->tm_sec);}
int get_week(){
time_t t;
struct tm *l;
t = time(&t);
l = localtime(&t);
return (l->tm_wday);}

#endif追答

clock t;
t.hour=get_hour();
t.minuts=get_minuts();
t.seconds=get_seconds();

把我发的第一段代码保存起来,以后可以直接调用里面的函数

追问

第二段是这样写吗?

追答

你完全照抄啊,,哈哈

前面加个 struct 试试

追问

还没有学时间函数

t未知啊?

追答

你的主函数里面没有clock那个结构吧,这个结构要写进去才行啊。。。

strucr clock{
int ....
省略。。。
}

main(){}

追问

这样?

追答

唉,不是不是

等我回去以后,写个完整的给你好了

追问

把第一段放进
struct clock{

};里吗?

追答

你发的照片的那个时钟结构,第一个照抄

追问

5 18 F:\C++(download)\临时编程文件\2.c [Error] expected ':', ',', ';', '}' or '__attribute__' before '{' token

int get_year(){

这句怎么错了?

追答

唉。我发给你的第一段代码你保存为头文件,然后在你的主程序里面包含它

追问

怎么保存为头文件?没学

追答

晕,,,你上几年级啊?

追问

大一

追答

#include
#include
struct clock {
int hour;
int minuts;
int seconds;};
int main(){
struct clock t;

time_t ti;
struct tm *l;
ti=time(&ti);
l = localtime(&ti);
t.hour=l->tm_hour;
t.minuts=l->tm_min;
t.seconds=l->tm_sec;
printf("time is %d:%d:%d",t.hour,t.minuts,t.seconds);

return 0;
}

好了,这个我测试过了。。。绝对通过。。。

追问

我想要的是时间会变化的程序……

追答

时间会变化?什么意思,不停的跳动的秒?

切,贪婪了。。。

追问

不会动的不叫时钟了……

编出来了,谢谢了

温馨提示:内容为网友见解,仅供参考
第1个回答  2014-10-29
我有追问

不发不采纳

追答

现在没有到中午吧,邮箱

相似回答