To allow appending to an empty list, the list pointer in the caller must be updated.
You must either take a pointer to the List
pointer: Appending(&head, element);
// Taking a double pointer to the initial element:
void Appending(Diary **List, Diary *Element) {
Diary *moving = *List;
if (moving == NULL) {
*List = Element;
} else {
while (moving->NextDiary != NULL)
moving = moving->NextDiary;
moving->Nextdiary = Element;
}
}
or you can return the updated List
pointer and update the list pointer in the caller by storing the return value into it: head = Appending(head, element);
// Returning an updated pointer to the initial element:
Diary *Appending(Diary *List, Diary *Element) {
Diary *moving = List;
if (moving == NULL) {
List = Element;
} else {
while (moving->NextDiary != NULL)
moving = moving->NextDiary;
moving->Nextdiary = Element;
}
return List;
}