我有一个结构数组 ( Training data[10]
),其中包含一些我想传递给函数的数据。
int convertTime(Time time)
{
minutes = time.seconds * 60;
// Takes data from data[0].time.seconds and converts them to minutes.
// My only problem is that I am being asked send a struct to this function, but I have to send the array because that's where all my data is stored
return minutes;
}
typedef struct
{
int seconds;
} Time;
typedef struct
{
Time time;
double distance;
} Training;
Training data[10];
Training input;
scanf("%d %lf", input.time.seconds, input.distance);
data[0].time.seconds = input.time.seconds;
data[0].distance = input.distance;
data[0].time.seconds
所以现在data[0].distance
包含我需要的所有数据。我只需要传递data[0].time.seconds
给函数,但在我的作业中,我被提示将结构发送Time
给函数,我不明白,因为Time
它只是存储临时数据?这是我要发送给函数的存储数据。
如何将秒转换为小时、分钟和秒?
time.hours = seconds / 3600;
time.minutes = (seconds - time.hours * 3600) / 60;
time.seconds = seconds - 3600 * time.hours - 60 * time.minutes;
这在我看来似乎是正确的,但它失败了。小时是正确计算的,但不是分钟和秒:(