Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prague/ Q&A

Name: Anonymous 2013-11-19 12:18

Ask /prog/ anything.

Although don't expect an answer or even a good one.

Also, keep it /prog/ related.

Name: Anonymous 2013-11-20 14:07

>>20
>>21
I see, so why doesn't this function work? First, I passed the Record * that I declared in main() to a function named input(Record *Something) so that I can ask for some data and call insert(). Whenever I try to print the data, the Record * I declared first in main() only seems to refer to NULL

int insert(Record *Phonebook, char * lname, char * fname, char * mobile)
{
/*
RETURN 0 IF SUCCESSFUL.
*/
Record *New, *Temp;

New = (Record *) malloc(sizeof (Record));

/* If malloc returns a null pointer... */
if (!New) {
return 1;
}

New->lastname = (char *) malloc(strlen(lname) + 1);
strcpy(New->lastname, lname);
printf("%s", New->lastname);
New->firstname = (char *) malloc(strlen(fname) + 1);
strcpy(New->firstname, fname);
New->mobilenum = (char *) malloc(strlen(mobile) + 1);
strcpy(New->lastname, mobile);
New->Next = NULL;

if (Phonebook == NULL) {
Phonebook = New;
} else {
Temp = Phonebook;
while (Temp->Next != NULL) {
Temp = Temp->Next;
}
Temp->Next = New;
}

return 0;
}

Did I fuck up the scoping and deleted the *Phonebook in input() when it ended?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List