function - Passing an element of an array of structs in C -
i trying pass 1 of 20 "database" structs made
here prototype function "add"
void add(struct database test);
i want pass database struct , i'll call "test"
here database structure
struct database { char id[6]; char duration[3]; }; main() { char menu; struct database employee[20]; // make 20 employee variables int = 0; /*a counter use edit structs ie a=2 "employee[a]" = "employee[2]" */
i call function this:
add(employee[a]); a++; /*once exits want go next employee variable increment counter */
the actual function looks this:
void add(struct database test) { static int = 0; printf("\nplease enter 5 digit employee number: "); scanf("%s", test[a].id); a++ }
while doing error:
error e2094 assignment.c 64: 'operator+' not implemented in type 'database' arguments of type 'int' in function add(database)
it says error @
scanf("%s", test[a].id);
thanks in advance help, , apolgise if have formatted wrong, still learning use stack overflow, sorry!
this need in order right:
void add(struct database* test) { printf("\nplease enter 5 digit employee number: "); scanf("%s",test->id); } int main() { ... int a; struct database employee[20]; (a=0; a<sizeof(employee)/sizeof(*employee); a++) add(&employee[a]); // or add(employee+a); ... }
Comments
Post a Comment