Hey I’m trying to create a SINGLY Linked List program that has 2 structs in it.
There is a struct that holds an Employee’s Information; like this
typedef struct{
int ID; //Employee ID, randomly generated 4 digit integer
char *firstName[25]; //Employee's first name
char *lastName[35]; //Employess's last name
char status; //AM/PM status, if valueof char:1=AM Employee,0=PM Employee
}EMPLOYEE;
Then there is a Linked List struct, which contains the Employee Information Struct AND a reference to a Linked List struct (I called it next); it looks like this:
struct LinkedList{
EMPLOYEE employee;
struct LinkedList *next;
};
In the main() function, I have to create TWO Linked List head node, because I have to have TWO Linked Lists, one for AM employees and one for PM employees, so I made this:
void main() {
struct LinkedList *AMHead = NULL; //I made this NULL for now, they will be allocated in create a LinkedListNode function.
struct LinkedList *PMHead = NULL;
}
So now is where I am having difficulty. Then there is a function that creates a Linked List Node, it can’t have parameters. It will use memory allocation to create the node, then I will ask user for employee information and initialize the employee struct portion of the Linked List node with the given info. I will then set the next pointer to NULL, and return a pointer to this new node. Here is what I wrote so far:
void createLinkedListNode(){
struct LList *node = (struct LList)*malloc(sizeof(struct LList));
//node created by allocating memory to struct
//prompt for all info required in employee struct
printf("Enter ID:\n");
printf("Enter first name:\n");
printf("Enter last name:\n");
printf("Enter status:\n");
};
So my questions are, do I have to create 2 nodes? One for the AM list and another for the PM list, or can I use the same node for both. And then how do I initialize the employee struct and store the info read. And did I create the structs and the head nodes correctly because I have 2 linked lists in a singly linked list program. Anything I should fix or any way I can make the code beter?
fgetsto read input, something likefgets(node->firstName, sizeof(node->firstName), stdin);Simplify and use only one ofEMPLOYEEandLListchar *firstName[25];-->char firstName[25];