Click here to Skip to main content
15,906,333 members

Comments by johnmolo (Top 2 by date)

johnmolo 26-Apr-13 12:09pm View    
ya sure I will add it now.
johnmolo 26-Apr-13 11:53am View    
Hi,thanks for the feedback this problem is really setting me back.I tried the above suggestions to the code:

int addContact(struct contact **theList)
{
struct contact *newContact, *curr;

// create the new structure
newContact = (struct contact *)malloc(sizeof(struct contact));
if( newContact == NULL )
{ // if true, then no memory left - oops
return(0);
}
// find the end of the list
curr = *theList;
// scroll through the list
if(curr != NULL)
{

while( curr->next != NULL)
{
curr = curr->next;
}

}
// now have the last contact
// add the new one here.
printf("\nEnter a surname: ");
fflush(stdin);
gets(newContact->sname);
printf("\nEnter a first name: ");
gets(newContact->fname);
printf("\nEnter a phone: ");
gets(newContact->phone);
printf("\nEnter a company: ");
gets(newContact->company);

// need to hook the new contact to
// end of list

if (curr == 0)
{
*theList = newContact;
newContact->next = NULL;
newContact->prev = NULL;
}
else
{
curr->next = newContact;
newContact->prev = curr;
newContact->next = NULL;
}
return(1);
}//add

But I'm getting the same error.What exactly am I doing wrong here in the function that the list isn't being passed?