gpt4 book ai didi

c - 我的程序可以编译,但时间和日期不会更新。有人可以告诉我哪里偏离路线了吗

转载 作者:行者123 更新时间:2023-11-30 21:09:33 26 4
gpt4 key购买 nike

我完成了我的代码并通过代码块运行它,没有错误,它在命令提示符屏幕上显示了我在代码中的日期和时间,但由于某种原因它不会更新。有人可以指出我正确的方向或告诉我我做错了什么吗?这是我认为已经解决的问题:

Write a function called clockKeeper that takes as its argument a dateAndTime structure. The function should call the timeUpdate function, and if the time reaches midnight, the function should call the dateUpdate function to switch over to the next day. Have the function return the updated dateAndTime structure and output it to the terminal.

#include <stdio.h>

int dt;

struct date
{
int day;
int month;
int year;
};

struct time
{
int seconds;
int minutes;
int hour;
};

struct dateAndTime {
struct date sdate;
struct time stime;
};

struct dateAndTime clockKeeper (struct dateAndTime dt)
{
struct time timeUpdate (struct time now); {
printf ("timeUpdate\n");
return now;
}

struct date dateUpdate (struct date today); {
printf ("dateUpdate\n");
return today;
}

dt.stime = timeUpdate (dt.stime);

if ( dt.stime.hour == 0 && dt.stime.minutes == 0 &&
dt.stime.seconds == 0 )
dt.sdate = dateUpdate (dt.sdate);

return dt;
}

int main (void)

int dt1;
int dt2;

{
struct dateAndTime dt1 = { { 12, 31, 2004 }, { 23, 59, 59 } };
struct dateAndTime dt2 = { { 2, 28, 2008 }, { 23, 59, 58 } };

printf ("Current date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n",
dt1.sdate.month, dt1.sdate.day, dt1.sdate.year,
dt1.stime.hour,
dt1.stime.minutes, dt1.stime.seconds);

dt1 = clockKeeper (dt1);

printf ("Updated date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n\n",
dt1.sdate.month, dt1.sdate.day, dt1.sdate.year,
dt1.stime.hour, dt1.stime.minutes, dt1.stime.seconds);

printf ("Current date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n",
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

dt2 = clockKeeper (dt2);

printf ("Updated date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n\n",
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

printf ("Current date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n",
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

dt2 = clockKeeper (dt2);

printf ("Updated date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n\n",
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

return 0;
}

最佳答案

看起来您正在尝试在clockKeeper 的定义中定义一个函数timeUpdate。当您编写时(更改缩进以消除混淆):

struct dateAndTime  clockKeeper (struct dateAndTime dt)
{
struct time timeUpdate (struct time now);
{ /* This brace may as well be deleted. */
printf ("timeUpdate\n");
return now;
} /* along with this one. */
...

您正在定义函数clockKeeper,在其中声明函数timeUpdate 的存在以及在clockKeeper 中执行的两个语句。 ClockKeeper 唯一要做的就是这两个语句。如果要定义函数timeUpdate,则需要将其移到clockKeeper定义之外,并删除左大括号之前的分号。您的代码可能还有许多其他问题,但这是一个很好的起点。

关于c - 我的程序可以编译,但时间和日期不会更新。有人可以告诉我哪里偏离路线了吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34304811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com