Originally Posted by
bluetxxth
Why is this happening? can you illustrate with an example which would be the correct way of making an array of structures while using typedef?
This is one correct way:
Code:
typedef struct employee {
int emp_index;
char name[30];
char address[100];
int age;
float salary;
} employee;
/* ... */
int main(int argc, char** argv) {
employee emp_struct[N];
/* ... */
Notice that emp_struct is now a local variable that you can pass appropriately to those functions that need to access it.
There is also this option:
Code:
typedef struct employee employee;
struct employee {
int emp_index;
char name[30];
char address[100];
int age;
float salary;
};
You can define emp_struct here if you want, but generally you should not because you should normally avoid global variables.