【发布时间】:2014-04-14 12:29:34
【问题描述】:
我试图传递我制作的 20 个“数据库”结构之一
这是我的函数“add”的原型
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: 'operator+' 未在函数 add(database) 中的“int”类型参数的“数据库”类型中实现
它说错误发生在
scanf("%s", test[a].ID);
提前感谢您的帮助,如果我格式错误,我很抱歉,仍在学习使用堆栈溢出,非常抱歉!
【问题讨论】:
-
为什么不能将结构指针传递为 void add(struct database *test);,更改 add(employee[a]);到 add(&employee[a]); 和 scanf("%s", test[a].ID);到 scanf("%s", test->ID);
标签: c function struct parameter-passing argument-passing