C 将两个结构数组作为参数传递给函数
所以我有时间结构数组,它包含hh,mm,ss格式的时间。 我做了一个函数timeDifference,以秒为单位计算时间差 在函数中,如何将参数作为两个时间结构传递 我正在尝试这样做,并得到函数的隐式声明错误C 将两个结构数组作为参数传递给函数,c,arrays,function,pointers,struct,C,Arrays,Function,Pointers,Struct,所以我有时间结构数组,它包含hh,mm,ss格式的时间。 我做了一个函数timeDifference,以秒为单位计算时间差 在函数中,如何将参数作为两个时间结构传递 我正在尝试这样做,并得到函数的隐式声明错误 int timeDifference(struct time T[i], struct time T[j]); T[i],T[j]可以参照两个时间结构T[0]和T[1],如下所示: struct time{ int hours; int minutes; int seconds; };
int timeDifference(struct time T[i], struct time T[j]);
T[i],T[j]可以参照两个时间结构T[0]和T[1],如下所示:
struct time{
int hours;
int minutes;
int seconds;
};
int timeDifference(struct time T[i], struct time T[j]);
int main(){
struct time T[8]; // 9 time structures i.e 9 time values in hh,mm,ss
T[0].hours=2;
T[0].minutes= 00; // T[0]
T[0].seconds=00;
T[1].hours=3;
T[1].minutes=10; // T[1]
T[1].seconds=00;
timeDifference(T[0], T[1]); Function call in main for evaluating difference
.
.
.
}
int timeDifference(struct time T[i], struct time T[j]) // function for
// calculating difference
{
.
.
}
我认为它使用指针,我是C语言的新手,因此有人能推荐一些在线资源来理解指针吗?
谢谢您正在使用一个编译器尚未看到声明的函数。 您需要在main之前声明函数,如下所示:
//rest of your code
int timeDifference(struct time T[], struct time T[]);
int main(){
//rest of your code
}
c有指针并不意味着你总是需要它们。在这里,您不需要。@EOF,函数不会接受这样的参数,获取错误和警告,隐式声明。
int-timeDifference(结构时间a,结构时间b)
。另外,请确保原型可用于main()
。这也可以,但是我可以将数组索引作为参数传递吗@我已经做了,伙计,抱歉忘了展示;在开头的声明问题@k0staa