int main() { askForName(std::cout); sayGreeting(std::cout, inputName(std::cin)); }
int main() { FILE *fp; FILE *fp2; char* file_name = "students.txt"; char* file_name2 = "log.txt"; int studentId; char name[30]; char class[10]; char department[10]; int r; StudentNode temp; StudentNode* result; int i; int loop; int userChoice; //Initialize index array for (i = 0; i<20; i++) { indexArray[i].r = i; indexArray[i].node = NULL; cur[i] = NULL; } printf("Begin of program\n\n"); //Try to open file to read if ((fp = fopen(file_name, "r")) == NULL) { printf("No such file\n"); exit(1); } //Add students to their corespoding indexes while (fscanf(fp, "%d:%[^:]:%[^:]:%[^:\n]", &studentId, name, class, department) == 4) { addStudent(studentId, name, class, department); } //Link indexes together linkIndexes(); //Menu loop = 1; while (loop) { printf ("******************************\n* What do you wanna do? *\n* 1- Add student *\n* 2- Delete student *\n* 3- Find student *\n* 4- Edit student *\n* 5- Student list *\n* 6- Exit *\n******************************"); printf("\nYour choice: "); scanf("%d%*c", &userChoice); switch (userChoice) { case 1: studentId = askForId(); temp = findStudentById(studentId); if (temp == NULL) { strcpy(name, askForName()); strcpy(class, askForClass()); strcpy(department, askForDepartment()); addStudent (studentId, name, class, department); linkIndexes(); addStudentToFile(studentId, name, class, department, file_name); makeLog(studentId, "APPEND", file_name2); printf("Add success!\n"); } else printf("ID already existed!\n"); break; case 2: studentId = askForId(); if (deleteStudent(studentId) == 1) { deleteStudentFromFile(studentId, file_name); makeLog(studentId, "DELETE", file_name2); printf("Delete success!\n"); } else printf("Can't find any student with given ID!\n"); break; case 3: printf("\nFind by which criteria?\n1- Student ID\n2- Name\n3- Class\n4- Department\n5- Back to menu\nYour choice: "); scanf("%d%*c", &userChoice); switch (userChoice) { case 1: studentId = askForId(); temp = findStudentById(studentId); printf("\nResult:\n"); if (temp != NULL) { printf("%-10d | %-30s | %-10s | %-10s\n", temp->studentId, temp->name, temp->class, temp->department); } else
int main() { askForName(std::cout); sayGreeting(std::cout, inputName(std::cin), inputName(std::cin)); // order is unspecified }