void save_data(void) { puts("保存数据"); printf(" 请输入文件名"); char filename[256]; scanf("%s", filename); FILE *fp = fopen(filename, "r"); if (fp == NULL) { perror(filename); return; } for (int i = 0; i < num_parts; i++) { fprintf(fp, "%d,%s,%d\n", stu[i].number, stu[i].name, stu[i].score); } fclose(fp); printf("保存%d 成功", num_parts); } //排序 void sort_data(void) { printf("排序\n"); for (int i = 0; i < num_parts; i++) { int change = 0; static struct students t; for (int j = 0; j < num_parts - i - 1; j++) { if (stu[j].number > stu[j + 1].number) { t = stu[j + 1]; stu[j + 1] = stu[j]; stu[j] = t; change = 1; } } if (!change) break; } for (int i = 0; i < num_parts; i++) { int change = 0; static struct students t; for (int j = 0; j < num_parts - i - 1; j++) { if (stu[j].score > stu[j + 1].score) { t = stu[j + 1]; stu[j + 1] = stu[j]; stu[j] = t; change = 1; } } if (!change) break; } printf("排序已完成"); } void make_chart(void) { printf("NUMBER | NAME score\n"); for (int i = 0; i < num_parts; i++) { printf("%d | %s ", stu[i].number, stu[i].name); for (int j = 0; j < stu[i].score; j++) { printf("*"); } printf("\n"); } printf("图表\n"); } int confirm(const char *msg) { char c = 'n'; // 默认选择是 no printf("%s(Y/N): ", msg); // 提示输入 yes/no 进行确认 scanf(" %c%*[^\n]", &c); // 读取第一个字符,忽略剩余字符 return c == 'y' || c == 'Y'; // 返回确认结果 }