Dynamic Linked Lists and File Manipulation/assign5.c
void loadStudentInfo(const char *fileName, StudentInfoPtr *startStudentInfoPtr) {
    
    FILE *filePtr;        
     
    if ((filePtr = fopen(fileName, "r")) == NULL) puts("FILE COULD NOT BE OPENED");
    else {
        while(1) {
            StudentInfoPtr newStudentInfoPtr = NULL;    

            //If no space is available return
            if ((newStudentInfoPtr = malloc(sizeof(StudentInfo))) == NULL) {
                puts("Unable to allocate memory");
                break;
            }
            
            //Reads student info
            {
                fscanf(filePtr, "%9s", newStudentInfoPtr->studentId);
                
                //Tests for end of file marker
                if (!strcmp(newStudentInfoPtr->studentId, EOF_MARKER)) {
                    fclose(filePtr);
                    break;
                }
                
                fscanf(filePtr, "%20s", newStudentInfoPtr->firstName);
                fscanf(filePtr, "%25s", newStudentInfoPtr->lastName);
                
                formatName(newStudentInfoPtr->firstName);
                formatName(newStudentInfoPtr->lastName);
               
                fscanf(filePtr, "%d", &newStudentInfoPtr->numOfAttentingCourses);
            }
            
            //Reads each course data
            for (int i = 0; i < newStudentInfoPtr->numOfAttentingCourses; i++) {
                fscanf(filePtr, "%29s %d", newStudentInfoPtr->courseInfoArr[i].courseName, &(newStudentInfoPtr->courseInfoArr[i]).courseId);
                convertToUppercase(newStudentInfoPtr->courseInfoArr[i].courseName);
            }
                        
            newStudentInfoPtr->next = NULL;
            
            if(searchStudentId(startStudentInfoPtr, newStudentInfoPtr->studentId) == NULL) {               
                addStudent(startStudentInfoPtr, newStudentInfoPtr);
            }
            else printf("%s %s", "Duplicate student ID: ", newStudentInfoPtr->studentId);
        }
        
        fclose(filePtr);
    }
}
/*
    loadStudentInfo: reads student info from a sorted text file into a linked list
    input: the file name (fileName), the beginning of the linked list (startStudentInfoPtr)
*/
reads student info from a sorted text file into a linked list
input: the file name (fileName), the beginning of the linked list (startStudentInfoPtr)
reads student info from a sorted text file into a linked list input : the file name ( fileName ) the beginning of the linked list ( startStudentInfoPtr )
void loadStudentInfo(const char *fileName, StudentInfoPtr *startStudentInfoPtr) {
    FILE *filePtr;        
    if ((filePtr = fopen(fileName, "r")) == NULL) puts("FILE COULD NOT BE OPENED");
    else {
        while(1) {
            StudentInfoPtr newStudentInfoPtr = NULL;    
            if ((newStudentInfoPtr = malloc(sizeof(StudentInfo))) == NULL) {
                puts("Unable to allocate memory");
                break;
            }
            {
                fscanf(filePtr, "%9s", newStudentInfoPtr->studentId);
                if (!strcmp(newStudentInfoPtr->studentId, EOF_MARKER)) {
                    fclose(filePtr);
                    break;
                }
                fscanf(filePtr, "%20s", newStudentInfoPtr->firstName);
                fscanf(filePtr, "%25s", newStudentInfoPtr->lastName);
                formatName(newStudentInfoPtr->firstName);
                formatName(newStudentInfoPtr->lastName);
                fscanf(filePtr, "%d", &newStudentInfoPtr->numOfAttentingCourses);
            }
            for (int i = 0; i < newStudentInfoPtr->numOfAttentingCourses; i++) {
                fscanf(filePtr, "%29s %d", newStudentInfoPtr->courseInfoArr[i].courseName, &(newStudentInfoPtr->courseInfoArr[i]).courseId);
                convertToUppercase(newStudentInfoPtr->courseInfoArr[i].courseName);
            }
            newStudentInfoPtr->next = NULL;
            if(searchStudentId(startStudentInfoPtr, newStudentInfoPtr->studentId) == NULL) {               
                addStudent(startStudentInfoPtr, newStudentInfoPtr);
            }
            else printf("%s %s", "Duplicate student ID: ", newStudentInfoPtr->studentId);
        }
        fclose(filePtr);
    }
}
void loadStudentInfo ( const char * fileName , StudentInfoPtr * startStudentInfoPtr ) { FILE * filePtr ; if ( ( filePtr = fopen ( fileName , " " ) ) == NULL ) puts ( " " ) ; else { while ( 1 ) { StudentInfoPtr newStudentInfoPtr = NULL ; if ( ( newStudentInfoPtr = malloc ( sizeof ( StudentInfo ) ) ) == NULL ) { puts ( " " ) ; break ; } { fscanf ( filePtr , " " , newStudentInfoPtr -> studentId ) ; if ( ! strcmp ( newStudentInfoPtr -> studentId , EOF_MARKER ) ) { fclose ( filePtr ) ; break ; } fscanf ( filePtr , " " , newStudentInfoPtr -> firstName ) ; fscanf ( filePtr , " " , newStudentInfoPtr -> lastName ) ; formatName ( newStudentInfoPtr -> firstName ) ; formatName ( newStudentInfoPtr -> lastName ) ; fscanf ( filePtr , " " , & newStudentInfoPtr -> numOfAttentingCourses ) ; } for ( int i = 0 ; i < newStudentInfoPtr -> numOfAttentingCourses ; i ++ ) { fscanf ( filePtr , " " , newStudentInfoPtr -> courseInfoArr [ i ] . courseName , & ( newStudentInfoPtr -> courseInfoArr [ i ] ) . courseId ) ; convertToUppercase ( newStudentInfoPtr -> courseInfoArr [ i ] . courseName ) ; } newStudentInfoPtr -> next = NULL ; if ( searchStudentId ( startStudentInfoPtr , newStudentInfoPtr -> studentId ) == NULL ) { addStudent ( startStudentInfoPtr , newStudentInfoPtr ) ; } else printf ( " " , " " , newStudentInfoPtr -> studentId ) ; } fclose ( filePtr ) ; } }
loadStudentInfo: reads student info from a sorted text file into a linked list
input: the file name (fileName), the beginning of the linked list (startStudentInfoPtr)
loadStudentInfo : reads student info from a sorted text file into a linked list input : the file name ( fileName ) the beginning of the linked list ( startStudentInfoPtr )
//If no space is available return //Reads student info //Tests for end of file marker //Reads each course data