add to end of linked list
this is what i did to add to the end of a linked list but when i print it out it doesn't come out right. this is my code:
Code:
/*functions allows user to add members to the end of list*/
struct member_account *add_to_end(struct member_account *list,char *last, char *first, double balance, int count3) {
struct member_account *current;
struct member_account *new_list=NULL;
new_list = (struct member_account *)malloc(sizeof(struct member_account));
if(list == NULL) {
list = (struct member_account *)malloc(sizeof(struct member_account));
strcpy(list->member_last,last);
strcpy(list->member_first,first);
list->member_balance=balance;
list->next = NULL;
return(list);
}
else {
current = (struct member_account *)malloc(sizeof(struct member_account));
strcpy(current->member_last,last);
strcpy(current->member_first,first);
current->member_balance=balance;
current->next=list;
}
while(list!=NULL){
current=list;
list=list->next;
current->next = new_list;
new_list= current;
}
return(new_list);
count3++;
} /* end add_to_end*/
can any one explain to me how would i go about adding to the end of the list. THANKS