both methods work fine but I am having trouble stopping a unhandled exception after deleting all nodes, the lable I added in display should solve this but I'm still getting the exception:
void DisplayAllEmp(struct node* head){
struct node *temp;
temp =(struct node*)malloc(sizeof(struct node));
temp = head;
if( temp == NULL ){ //check if theres anything in the list
delerr: printf("\nDatabase is empty.\n"); // notify the DB is empty
}
else{
while( temp!= NULL ) //loop through all employees and print them out
{
if( temp->empId == NULL ){ goto delerr; } // for catching error following delete employee when you display the DB
printf("\nId: %d Address: %s Department: %d DOJ: %d/%d/%d Salary: %d Email: %s", temp->empId, temp->address, temp->depart, temp->day,temp->mounth,temp->year, temp->salary, temp->email); // show the employee
temp = temp->next;
}//while end
}
}
void DeleteEmp(struct node* head, int tempID){
struct node *curNode = head;
struct node *prevNode = curNode;
while (curNode != NULL) {
if(curNode->empId == tempID) {
prevNode->next = curNode->next;
if (prevNode){// remove the node from the list
prevNode->next = curNode->next;
}
else{
head = curNode->next;
}
free(curNode);
printf("Employee %d removed from database", tempID);
return;//assuming empId is unique return after you flound it.
}
prevNode = curNode;
curNode = curNode->next;
}
}