我试图传递我制作的 20 个“数据库”结构之一
这是我的函数“add”的原型(prototype)
void add(struct database test);
我想传递我的数据库结构,现在我只称它为“测试”
这是我的数据库结构
struct database
{
char ID[6];
char Duration[3];
};
main()
{
char menu;
struct database employee[20]; // I make 20 employee variables
int a = 0; /*A counter I use to edit certain structs
ie a=2 "employee[a]" = "employee[2]" */
然后我这样调用这个函数:
add(employee[a]);
a++; /*Once it exits this I want it to go to the next employee
variable so I increment the counter */
实际的功能是这样的:
void add(struct database test)
{
static int a = 0;
printf("\nPlease enter a 5 digit employee number: ");
scanf("%s", test[a].ID);
a++
}
在执行此操作时出现错误:
错误 E2094 Assignment.c 64:函数 add(database) 中“int”类型参数的“operator+”未在类型“database”中实现
它说错误在
scanf("%s", test[a].ID);
在此先感谢您的帮助,如果我的格式有误,我深表歉意,仍在学习如何使用堆栈溢出,非常抱歉!
最佳答案
这是你需要做的才能让它正确:
void add(struct database* test)
{
printf("\nPlease enter a 5 digit employee number: ");
scanf("%s",test->ID);
}
int main()
{
...
int a;
struct database employee[20];
for (a=0; a<sizeof(employee)/sizeof(*employee); a++)
add(&employee[a]); // or add(employee+a);
...
}
关于c - 在 C 中传递结构数组的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23060128/