HI there MK,
I have been trying to implement what you suggested yesterday but I still have problems.
Based on this structure:
Code:
struct employee {
int emp_index; //To assign a value to each employee for a later "pointing"
char name[30];
char address[100];
int age;
float salary;
} emp_struct[N];
First I made two functions one to make take input from the user to decide the size of the staff
Code:
// Takes imput that establishes the size of the staff
void staff_size() {
printf("What is the size of your staff?: ");
scanf("%d", &emp_num);
}
Second I fill the staff like this (I think this will be the array of structures):
Code:
//Fills staff with desired size of elements - This is the array of structures (emp_struct)
void staff_create() {
printf("Populating staff......... \n\n");
for (d = 1; d <= emp_num; d++)
emp_struct[emp_num];
}
Then I thought to make another function for the array of pointers like this:
Code:
// This is an array of pointers. As an index it will have the index value of the array of structures
void fill_emp_struct(void *emp_ptrs, struct employee emp_struct) {
for (d = 0; d <= emp_num; d++)
emp_ptrs[emp_struct[d].emp_index] = &emp_struct[d];
}
This above, however, gives me an error which says;
'main.cpp:52: error: no match for 'operator[]' in 'emp_struct[d]''
I don't even think its necessary but I thought that perhaps I could make the function return an employee and call it within the main function instead of coding there... what do you think?
Below within the main function I have:
Code:
struct employee *ptr = &emp_struct[d]; // Used for an array of structures. Here ptr points at the address of emp_struct
struct employee * emp_ptrs[N]; //Declares a pointer of type employee which will be used for the array of pointers.
emp_ptrs[emp_struct[d].emp_index] = &emp_struct[d]; //Initializes the pointer above, emp_ptrs will have as index, emp_index
// emp_ptrs will be pointing to &emp_stuct[d]
I think this time I decared and initialized the pointers correctly...
Then, I think this is my second probem, I believe I did not understand how to printf, or 'extract' if you will, the contents of the pointer that points to the &emp_struct[d].emp_index which is theoretically the employee I have scanf'ed and the one I want to view.
Code:
printf("Enter empoyee you want to inspect: \n");
// this bit has to point to the chosen employee in the employee array. Make use of the index
scanf("%d", &emp_struct[d].emp_index); // scans the index value desired
for (d = 0; d <= emp_num; d++) {//this is the ammount of employees to output on the screen.
}
printf("Employee summary: %d\n", ptr -> &emp_struct[d].emp_index);//Prints desired employee << HERE IS THE PROBLEM
for the code above I get this error: main.cpp:177: error: expected unqualified-id before '&' token
What is I do wrong? Can u give me some more ideas?