int solve() { int choice; Result person[MAXLENGTH]; int n; int case1 = 0; int currentIndex = 0; while(1) { switch(choice = menu()) { case 1: printf("You choose option %d\n", choice); getStudentInformation(person, ¤tIndex); printStudentList(person, currentIndex); case1 = 1; continue; case 2: printf("You choose option %d\n", choice); if(!case1) { printf("Please choose case 1 first!\n"); continue; } searching(person, currentIndex); continue; case 3: printf("You choose option %d\n", choice); if(!case1) { printf("Please choose case 1 first!\n"); continue; } findScholashipStudent(person, currentIndex); printStudentList(person, currentIndex); continue; case 4: printf("You choose option %d\n", choice); if(!case1) { printf("Please choose case 1 first!\n"); continue; } fixGrade(person, currentIndex); printStudentList(person, currentIndex); continue; case 5: printf("You choose option %d\n", choice); if(!case1) { printf("Please choose case 1 first!\n"); continue; } deleteStudent(person, ¤tIndex); printStudentList(person, currentIndex); continue; case 6: printf("You choose option %d\n", choice); break; default: printf("Invalid choice!\n"); continue; } break; } return 0; }
int cli_print_all(StudentList* sl) { // TODO: this to return status code printStudentList(sl); return 0; }
int main(void) { char buf[256]; int lineCount = 0; int fileOpenResult = 0; FILE *fileRead = NULL, *fileWrite = NULL; StudentList studentList; studentList.count = 0; studentList.firstStudent = NULL; studentList.lastStudent = NULL; // student list 초기화 fileOpenResult = openStudentFile(&fileRead, &fileWrite); if (fileOpenResult == -1) return -1; // data.txt 읽어오기, 없으면 만들기, 만들기 실패하면 종료하기 if (fileOpenResult == 0) { while (fgets(buf, sizeof(buf), fileRead) != NULL) // file 읽어서 구조체 할당하고 list에 추가하기 { if (lineCount++ == 0) continue; // 첫줄 무시 Student *s = parseStudentStr(buf); addStudentToList(s, &studentList); } } if (fileRead) fclose(fileRead); if (fileWrite) fclose(fileWrite); // main program loop int choice = 0; int changeExists = 0; while (choice != 9) { runMainMenu(&choice); switch (choice) { case 1: printStudentList(&studentList); break; case 2: addNewStudent(&studentList); changeExists++; break; case 3: modifyStudentInfo(&studentList); changeExists++; break; case 4: deleteStudentInfo(&studentList); changeExists++; break; case 5: saveListToFile(&studentList); changeExists = 0; break; case 9: if (onQuit(changeExists)) saveListToFile(&studentList); break; default: printf("Invalid choice!\n"); break; } } cleanupOnExit(&studentList, fileRead, fileWrite); return 0; }