我正在学习一段代码,不知道如何仅使用一个函数来实现此功能?如何将参数传递给函数?
#include <stdio.h>
struct colleagues {
int female[10];
int male[10];
} teams[20];
void func(int count[])
{
for (int i = 0; i < 10; i++) {
printf("%d\n", count[i]);
}
}
//FIXME
void showCnt(void (*function)(int *), int XXX[])
{
for (int n = 0; n < 20; n++) {
func(teams[n].XXX);
}
}
int main()
{
//How can i just use only one function showCnt to do this work???, I'm so appreciated.
//***FIXME, How can i pass parameters "teams.female" to showCnt???***
showCnt(function, teams.female);
showCnt(function, teams.male);
return 0;
}
抱歉,我没说清楚。我不知道如何将参数“ teams.male”作为数组传递给showCnt(),我想知道如何分别两次调用showCnt()来打印信息。
例如,首先,它调用showCnt(teamXX.female),其次,它调用showCnt(teamXXX.male)。我不知道是否可以将参数传递给showCnt()以使“ func(team [n] .male)”和“ func(team [n] .female)”正常工作。
如果我理解正确的话,你要只调用showCnt
为
showCnt(function);
它应该同时打印teams.female
和teams.male
?
然后从函数中删除(错误)count
参数showCnt
。然后使用和在showCnt
调用循环中function
两次。teams[n].female
teams[n].male
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句