0
struct Employee
{
   /* Employee details */
   char name[MAX_NAME_LENGTH+1]; /* name string */
   char sex;                     /* sex identifier, either 'M' or 'F' */
   int  age;                     /* age */
   char job[MAX_JOB_LENGTH+1];   /* job string */

   struct Employee *prev, *next;
};

static void menu_add_employee(void)
{
    static struct Employee *employee_list = NULL;
    {
        struct Employee *new;

        new = (struct Employee *) malloc ( sizeof(struct Employee) );
        strcpy (new -> name, "Sadra Mostashar");
        new -> sex = 'M';
        new -> age = 20;
        strcpy (new -> job, "Student");

        /*add first employee to doubly linked list*/
        new -> prev = NULL;
        new -> next = employee_list;
        employee_list = new;
        free ( new );
}

static void menu_print_database(void)
{/*Here's my question, How do I print the above structure in this function by calling that structure?*/
    struct Employee *employee_list;
    printf("Name: %s\n", employee_list->name);
    printf("Sex:  %c\n", employee_list->sex);
    printf("Age:  %i\n", employee_list->age);
    printf("Job:  %s\n", employee_list->job);
}

Edited by Reverend Jim: Fixed formatting

2
Contributors
1
Reply
4
Views
7 Years
Discussion Span
Last Post by Adak
0

You have a double linked list. If you want to print another node of that list (another structure's worth of data), then go to that node, and print it.

You don't print a structure, from another structure. Structures just hold data, and are not "Objects" with the ability to print other structures.

You use the dot member operator to access each member of the structure, including printing it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.