Dynamic Linked Lists and File Manipulation/assign5.c
void terminate(StudentInfoPtr *head) {
    
    printf("%s", "Save students to file before exiting (Y/N) ? ");
    
    char decision;
    scanf("%c", &decision);
    
    if(decision == 'y' || decision == 'Y') {
        saveStudentInfo(head);
        puts("Students saved!");
    }
    
    StudentInfoPtr currentStudentInfoPtr = *head;
    StudentInfoPtr hold = NULL;

    //de-allocates memory used
    while (currentStudentInfoPtr != NULL) {
        hold = (StudentInfoPtr) currentStudentInfoPtr->next;
        currentStudentInfoPtr = (StudentInfoPtr) currentStudentInfoPtr->next;
        free(hold);
    }
    
    *head = NULL;
    
    puts("Exiting...");
}
/*
    terminate: free the allocated space used in the linked list
    input: the beginning of the list (head)
*/
free the allocated space used in the linked list
input: the beginning of the list (head)
free the allocated space used in the linked list input : the beginning of the list ( head )
void terminate(StudentInfoPtr *head) {
    printf("%s", "Save students to file before exiting (Y/N) ? ");
    char decision;
    scanf("%c", &decision);
    if(decision == 'y' || decision == 'Y') {
        saveStudentInfo(head);
        puts("Students saved!");
    }
    StudentInfoPtr currentStudentInfoPtr = *head;
    StudentInfoPtr hold = NULL;
    while (currentStudentInfoPtr != NULL) {
        hold = (StudentInfoPtr) currentStudentInfoPtr->next;
        currentStudentInfoPtr = (StudentInfoPtr) currentStudentInfoPtr->next;
        free(hold);
    }
    *head = NULL;
    puts("Exiting...");
}
void terminate ( StudentInfoPtr * head ) { printf ( " " , " " ) ; char decision ; scanf ( " " , & decision ) ; if ( decision == ' ' || decision == ' ' ) { saveStudentInfo ( head ) ; puts ( " " ) ; } StudentInfoPtr currentStudentInfoPtr = * head ; StudentInfoPtr hold = NULL ; while ( currentStudentInfoPtr != NULL ) { hold = ( StudentInfoPtr ) currentStudentInfoPtr -> next ; currentStudentInfoPtr = ( StudentInfoPtr ) currentStudentInfoPtr -> next ; free ( hold ) ; } * head = NULL ; puts ( " " ) ; }
terminate: free the allocated space used in the linked list
input: the beginning of the list (head)
terminate : free the allocated space used in the linked list input : the beginning of the list ( head )
//de-allocates memory used