Quote Originally Posted by bluetxxth View Post
Having changed initial value in the for loop to d=0, now I get a memory location as an outptut for the pointer
That's what %p does -- it prints the memory address in a pointer. It's only useful for debugging and not for "normal" output.

You want to do something more like:
Code:
printf("Employee summary\nName: %s\nAge: %d\n",ptr->name,ptr-age);
I think you are a little confused about something here:
Code:
truct employee {
    int emp_index; //To assign a value to each employee for a later "pointing"
    char name[30];
Kind of hard for me to see what purpose this serves.

A more serious problem:
Code:
 void *ptr = &emp_ptr[d]; // here ptr points at the address of the array of employees
    ptr = malloc(sizeof (struct employee) * d); // memory allocation for the previous line - is this right?
First, you have ptr pointing to a member of emp_ptr (which this is a bad name, it should be "emp_struct" or "emp_rec" or just "employee" -- it is not a ptr). Okay. But every time you do this:

ptr =

You are reassigning the ptr. Meaning it is no longer assigned (=) to whatever it was previously. So the initial assignment to &emp_ptr[d] is meaningless.

Even worse, then you do this:
Code:
ptr = &emp_ptr[d];
I can see why, and that is okay in itself, but you just assigned ptr some memory with malloc! Guess what happens to that: it still exists and is reserved, but you have no pointer to it anymore, because ptr now points to (=) something else. That is called a memory leak because that malloc'd memory is now unusable, and cannot be freed. You have no way to refer to it.

So for sure get rid of that malloc call. I don't think you need a seperate "ptr" at all.

AFAICT, all you need to do here is this:

- you have your array, emp_ptr.
- ask for a record number and put that into a seperate, stand-alone int (d)
- now show emp_ptr[d]

So, no need for:
1) emp_ptr.emp_index
2) ptr