Here's the code i'm working on. As far as I can tell the problem concerns passing in 'head' to 'insertEntry', or maybe it's just passing 'head' to any function - I'm totally at a loss as to how to fix it. I haven't gotten around to filling in the 'removeEntry' function yet.
Code:
# include <stdio.h>
#include <stdlib.h>
struct entry{
int val;
struct entry* next;
};
void insertEntry(struct entry* this, struct entry* after);
void removeEntry(struct entry* after);
void printList(struct entry* head);
int main(){
struct entry* head;
struct entry* temp_ptr;
int i;
int val;
// initialize the beginning of the list
head = NULL;
// print the list
printList(head);
// insert 3 items
for( i=0; i<3; i++ ){
printf("Enter a value: ");
scanf(" %d", &val);
//allocate and initialize a new node
temp_ptr = (struct entry*) malloc(sizeof(struct entry));
temp_ptr->val = val;
//insert the new node into the list
insertEntry(temp_ptr, head);
}
// print the elements
printList(head);
// remove 3 items
// removeEntry(head);
// removeEntry(head);
// removeEntry(head);
//print the list
printList(head);
return 0;
}
void insertEntry(struct entry* this, struct entry* after){
this->next = after->next;
after->next = this;
}
void removeEntry(struct entry* after){
}
void printList(struct entry* head){
struct entry* curr = head->next;
printf("List is: ");
if(!curr){
printf("EMPTY\n");
return;
}
while(curr){
printf("%d ",curr->val);
curr = curr->next;
}
printf("/n");
}