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++;
can any one explain to me how would i go about adding to the end of the list. THANKS

2. Code:
```    new_list = (struct member_account *)malloc(sizeof(struct member_account));

if(list == NULL) {
list = (struct member_account *)malloc(sizeof(struct member_account));```
If you don't have a list to start with, you allocate a node. But you just allocated a node for new_list. So you really shouldn't have 2 nodes now, you should only have one.

To find the end of a list, you should do:
Code:
```for( n = firstnode; n && n->next; n = n->next )
; /* do nothing, the loop is doing it for you */
if( n == NULL )
/* the list was empty in the first place */
else
/* n is pointing at the last node, n->next is NULL */```

Quzah.

3. thanks for you replay. can you explain to me what you did with the for loop. you have set the n to a pointer which is firstnode, and then i am not sure what you have done after that.

4. how would you delete a post on this websit

5. Originally Posted by johnhuge
how would you delete a post on this websit
If you ever expect anyone to help you here again, DO NOT DELETE YOUR INITIAL POST. There is no good reason to do so, and if you are doing it for a bad reason, you should not be posting anything to begin with.

6. *original code restored; thread closed*