gpt4 book ai didi

c - 静态声明遵循非静态声明错误消息

转载 作者:行者123 更新时间:2023-11-30 15:34:37 24 4
gpt4 key购买 nike

编译器给我一条错误消息

line 20: "static declaration of ‘timeDifference’ follows non-static declaration"

然后是另一个

line 12: "previous declaration of ‘timeDifference’ was here"

我知道这与我的函数“timeDifference”有关。这是我的代码:

#include <stdio.h>

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

main ()
{
int timeDifference (struct time diff);

struct time early, late, difference;

printf ("Enter Start Time hh:mm:ss ");

scanf ("%d:%d:%d", &early.hours, &early.minutes, &early.seconds);

printf ("Enter End Time hh:mm:ss ");

scanf ("%d:%d:%d", &late.hours, &late.minutes, &late.seconds);

int timeDifference (struct time diff)
{
if (late.seconds < early.seconds)
late.seconds += 60;
late.minutes -= 1;
if (late.minutes < early.minutes)
late.minutes += 60;
late.hours -= 1;
if (late.hours < early.hours)
late.hours += 24;

diff.seconds = late.seconds - early.seconds;
diff.minutes = late.minutes - early.minutes;
diff.hours = late.hours - early.hours;
}

return 0;
}

最佳答案

在 C 语言中,一个函数不能包含在另一个函数中。第 12 行的 timeDifference 声明以及从第 20 行开始的函数本身(定义)需要移至 main()函数。

关于c - 静态声明遵循非静态声明错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23206004/

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