概要
- 每种删增改查都有两种以上的操作,写的很繁琐,但是已经不愿意再整理了,就当练习打字速度了。
- 你需要的操作,1,在代码文件存在的目录下,建立两个student.txt和extra.txt。2,复制粘贴所有代码,然后编译运行即可
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
char res[12][30] = {
{"序号"}, {"姓名"}, {"性别"}, {"单位"}, {"省份"}, {"电话"}, {"邮箱"}, {"身份证号码"}, {"住宿"}, {"报道时间"}, {"返程时间"}, {"是否订票"}
};
char totprovince[39][20] = {{"山东"}, {"天津"}, {"河北"}, {"山西"}, {"内蒙"}, {"辽宁"}, {"上海"}, {"江苏"}, {"浙江"}, {"安徽"}, {"福建"}, {"江西"}, {"河南"}, {"湖北"}, {"湖南"}, {"广东"}, {"广西"}, {"海南"}, {"重庆"}, {"四川"}, {"贵州"}, {"云南"}, {"西藏"}, {"陕西"}, {"甘肃"}, {"甘肃"}, {"青海"}, {"新疆"}};
char seis[3][4] = { {"男"}, {"女"} };
char yseorno[4][4] = {
{
"是"
},
{
"否"
}
};
struct nodes {
int num;
char phonenum[40], idcard[20];
char name[20], workplace[20], province[20], email[30], starttime[30], sex[20], ifstay[10];
} stu[50];
struct extra {
char back[20], backtick[20];
} ppstu[50];
struct nodes empty;
void menu();
void insert();
void query();
void sort();
void re_move();
void change();
void change01();
void change02();
void print();
void agmenu() {
printf("\n\n\n");
printf("\t\t-------------------------------------------------\n");
printf("\t\t|| ---------------- ||\n");
printf("\t\t||**************参会信息管理系统***************||\n");
printf("\t\t|| ---------------- ||\n");
printf("\t\t|| 默认密码是123 ||\n");
printf("\t\t||**************1,信息录入功能****************||\n");
printf("\t\t||**************2,信息浏览功能****************||\n");
printf("\t\t||**************3,信息查询功能****************||\n");
printf("\t\t||**************4,信息排序功能****************||\n");
printf("\t\t||**************5,信息删除功能****************||\n");
printf("\t\t||**************6,信息修改功能****************||\n");
printf("\t\t||**************按下0键退出系统****************||\n");
printf("\t\t||***************按下9键清屏*******************||\n");
printf("\t\t||**************按*y*开始输入密码**************||\n");
}
void clear() {
system("cls");
agmenu();
}
int password ;
int correct = 123;
int main() {
menu();
printf("\n\t\t||输入你想要的功能");
int a ;
while (scanf("%d", &a) != EOF && a) {
if (a == 1) {
insert();
} else if (a == 2) {
print();
} else if (a == 3) {
query();
} else if (a == 4) {
sort();
} else if (a == 5) {
re_move();
} else if (a == 9) {
clear();
} else if (a == 6) {
change();
} else {
printf("\n\t\t||不存在这个功能请重新输入");
}
printf("\n\t\t||输入你想要的功能");
}
if (a == 0) {
printf("\n\t\t按下任意键退出程序");
}
return 0;
}
void menu() {
printf("\n\n\n");
printf("\t\t-------------------------------------------------\n");
printf("\t\t|| ---------------- ||\n");
printf("\t\t||**************参会信息管理系统***************||\n");
printf("\t\t|| ---------------- ||\n");
printf("\t\t|| 默认密码是123 ||\n");
printf("\t\t||**************1,信息录入功能****************||\n");
printf("\t\t||**************2,信息浏览功能****************||\n");
printf("\t\t||**************3,信息查询功能****************||\n");
printf("\t\t||**************4,信息排序功能****************||\n");
printf("\t\t||**************5,信息删除功能****************||\n");
printf("\t\t||**************6,信息修改功能****************||\n");
printf("\t\t||**************按下0键退出系统****************||\n");
printf("\t\t||***************按下9键清屏*******************||\n");
printf("\t\t||**************按*y*开始输入密码**************||\n");
getchar();
printf("\t\t||*****请输入你的密码 : ");
do {
scanf("%d", &password);
if (password == correct) {
printf("\n\t\t||密码正确");
break;
}
if (password == 0) {
printf("\t\t||按下任意键退出");
getchar();
exit(EXIT_FAILURE);
}
printf("\n\t\t||密码错误 , 请重新输入");
putchar('\n');
printf("\t\t||*****请输入你的密码 : ");
} while (password);
}
void insert() {
FILE *fp ;
FILE *ex ;
int m = 0;
int n = 0;
if ((fp = fopen("student.txt", "rb") ) == NULL) {
printf("\n\t\t||文件打开失败");
return;
}
while (!feof(fp)) {
if (fread(&stu[m], sizeof(struct nodes), 1, fp) == 1) {
m++;
}
}
if ((ex = fopen("extra.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
}
while (!feof(ex)) {
if (fread(&ppstu[n], sizeof(struct extra), 1, ex) == 1) {
n++;
}
}
fclose(fp);
fclose(ex);
if (m == 0) {
printf("\n\t\t||文件没有内容\n");
}
if ((fp = fopen("student.txt", "ab+")) == NULL) {
printf("\n\t\t||文件打开失败");
}
if ( (ex = fopen("extra.txt", "ab+")) == NULL) {
printf("\n\t\t||文件打开失败");
}
printf("\n\t\t||**********录入人员信息*********||");
printf("\n\t\t||****1,录入一名参会人员信息****||");
printf("\n\t\t||****2,停止录入退出到菜单******||");
printf("\n\t\t||*******************************||");
int ch;
scanf("%d", &ch);
while (ch == 1) {
printf("\n\t\t||输入报到序号:");
scanf("%d", &stu[m].num);
printf("\n\t\t||请输入姓名:");
scanf("%s", stu[m].name);
printf("\n\t\t||请输入性别:");
scanf("%s", stu[m].sex);
printf("\n\t\t||请输入工作单位:");
scanf("%s", stu[m].workplace);
printf("\n\t\t||请输入所属省份:");
scanf("%s", stu[m].province);
printf("\n\t\t||输入联系电话:");
scanf("%s", stu[m].phonenum);
printf("\n\t\t||请输入电子邮箱:");
scanf("%s", stu[m].email);
printf("\n\t\t||输入身份证号码:");
scanf("%s", stu[m].idcard);
printf("\n\t\t||是否需要住宿:(填是或者否)");
scanf("%s", stu[m].ifstay);
printf("\n\t\t||输入报到时间:");
scanf("%s", stu[m].starttime);
printf("\n\t\t||输入返程时间:");
scanf("%s", ppstu[n].back);
printf("\n\t\t||输入是否需要返程票(按下1为需要返程票,按下2为不需要返程票");
scanf("%s", ppstu[n].backtick);
if (fwrite(&stu[m], sizeof(struct nodes), 1, fp) != 1) {
printf("\n\t\t||文件写入失败");
getchar();
} else {
printf("\n\t\t||文件写入成功");
m++;
}
if (fwrite(&ppstu[n], sizeof(struct extra), 1, ex) != 1) {
printf("\n\t\t||文件保存失败");
} else {
printf("\n\t\t||文件写入成功");
}
printf("\n\t\t||是否继续录入参会人员信息(1或者2)");
scanf("%d", &ch);
}
fclose(fp);
fclose(ex);
}
void print() {
FILE *p ;
FILE *e ;
int m = 0, n = 0 ;
if ((p = fopen("student.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
return;
}
while (!feof(p)) {
if (fread(&stu[m], sizeof(struct nodes), 1, p) == 1 ) {
m++;
}
}
if ((e = fopen("extra.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
}
while (!feof(e)) {
if (fread(&ppstu[n], sizeof(struct extra), 1, e) == 1) {
n++;
}
}
fclose(p);
fclose(e);
if (m == 0) {
printf("\n\t\t||文件没有内容");
} else {
putchar('\n');
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
printf("%-3s\t%-6s\t%-2s\t%-6s\t%-6s\t%-11s\t%-11s\t%-18s\t%-2s\t%-4s\t%-4s\t%-3s\n", res[0], res[1], res[2], res[3], res[4], res[5], res[6], res[7], res[8], res[9], res[10], res[11]);
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
for (int i = 0 ; i < m ; i++) {
printf("%-3d\t", stu[i].num);
printf("%-6s\t", stu[i].name);
printf("%-2s\t", stu[i].sex);
printf("%-6s\t", stu[i].workplace);
printf("%-6s\t", stu[i].province);
printf("%-11s\t", stu[i].phonenum);
printf("%-11s\t", stu[i].email);
printf("-%18s\t", stu[i].idcard);
printf("%-4s\t", stu[i].ifstay);
printf("%-8s\t", stu[i].starttime);
printf("%-8s\t", ppstu[i].back);
printf("%-8s\t", ppstu[i].backtick);
printf("\n------------------------------------------------------------------------------------------------------------------------------------------------\n");
putchar('\n');
}
}
}
void query() {
printf("\n\n\n");
printf("\t\t-------------------------------------------------\n");
printf("\t\t|| ---------------- ||\n");
printf("\t\t||**************参会信息管理系统***************||\n");
printf("\t\t|| ---------------- ||\n");
printf("\t\t|| 现在是查询界面 ||\n");
printf("\t\t||**************1,查询特定序号的信息**********||\n");
printf("\t\t||**************2,查询姓名的信息**************||\n");
printf("\t\t||**************3,查询相同省份的信息*********||\n");
printf("\t\t||*********************************************||\n");
char s[2];
scanf("%s", s);
if (*s == '1') {
int flag = 1;
int num, m = 0 ;
FILE *f, *e;
if ((f = fopen("student.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
return ;
}
while (!feof(f)) {
if (fread(&stu[m], sizeof(struct nodes), 1, f) == 1 ) {
m++;
}
}
int n = 0 ;
if ((e = fopen("extra.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
}
while (!feof(e)) {
if (fread(&ppstu[n], sizeof(struct extra), 1, e) == 1) {
n ++;
}
}
fclose(f);
fclose(e);
printf("\n\t\t||请输入序号进行查询:");
scanf("%d", &num);
putchar('\n');
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
printf("%-3s\t%-6s\t%-2s\t%-6s\t%-6s\t%-11s\t%-11s\t%-18s\t%-2s\t%-4s\t%-4s\t%-3s\n", res[0], res[1], res[2], res[3], res[4], res[5], res[6], res[7], res[8], res[9], res[10], res[11]);
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
for (int i = 0 ; i < m ; i++) {
if (num == stu[i].num) {
flag = 0;
printf("%3d\t", stu[i].num);
printf("%6s\t", stu[i].name);
printf("%2s\t", stu[i].sex);
printf("%6s\t", stu[i].workplace);
printf("%6s\t", stu[i].province);
printf("%11s\t", stu[i].phonenum);
printf("%11s\t", stu[i].email);
printf("%18s\t", stu[i].idcard);
printf("%4s\t", stu[i].ifstay);
printf("%8s\t", stu[i].starttime);
printf("%8s\t", ppstu[i].back);
printf("%8s\t", ppstu[i].backtick);
printf("\n------------------------------------------------------------------------------------------------------------------------------------------------\n");
putchar('\n');
}
}
if (flag == 1) {
printf("\n\t\t||文件中不存在这个序号");
}
} else if (*s == '2') {
int m = 0 ;
char check[10];
int flag = 1;
FILE *f, *e;
if ((f = fopen("student.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
return ;
}
while (!feof(f)) {
if (fread(&stu[m], sizeof(struct nodes), 1, f) == 1 ) {
m++;
}
}
int n = 0 ;
if ((e = fopen("extra.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
}
while (!feof(e)) {
if (fread(&ppstu[n], sizeof(struct extra), 1, e) == 1) {
n ++;
}
}
fclose(f);
fclose(e);
printf("\n\t\t||请输入姓名进行查询:");
scanf("%s", check);
putchar('\n');
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
printf("%-3s\t%-6s\t%-2s\t%-6s\t%-6s\t%-11s\t%-11s\t%-18s\t%-2s\t%-4s\t%-4s\t%-3s\n", res[0], res[1], res[2], res[3], res[4], res[5], res[6], res[7], res[8], res[9], res[10], res[11]);
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
for (int i = 0 ; i < m ; i++) {
if (strcmp(check, stu[i].name) == 0) {
flag = 0;
printf("%3d\t", stu[i].num);
printf("%6s\t", stu[i].name);
printf("%2s\t", stu[i].sex);
printf("%6s\t", stu[i].workplace);
printf("%6s\t", stu[i].province);
printf("%11s\t", stu[i].phonenum);
printf("%11s\t", stu[i].email);
printf("%18s\t", stu[i].idcard);
printf("%4s\t", stu[i].ifstay);
printf("%8s\t", stu[i].starttime);
printf("%8s\t", ppstu[i].back);
printf("%8s\t", ppstu[i].backtick);
printf("\n------------------------------------------------------------------------------------------------------------------------------------------------\n");
putchar('\n');
}
}
if (flag == 1) {
printf("\n\t\t||文件中不存在这个序号");
}
} else if (*s == '3') {
int m = 0 ;
int n = 0 ;
FILE *f, *e ;
if ((f = fopen("student.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
}
while (!feof(f)) {
if (fread(&stu[m], sizeof(struct nodes), 1, f) == 1) {
m ++;
}
}
if ((e = fopen("extra.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
}
while (!feof(e)) {
if (fread(&ppstu[n], sizeof(struct extra), 1, e) == 1) {
n++;
}
}
fclose(e);
fclose(f);
int flag = 1;
printf("\n\t\t||请输入你想查询的省份");
char str[8];
scanf("%s", str);
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
printf("%-3s\t%-6s\t%-2s\t%-6s\t%-6s\t%-11s\t%-11s\t%-18s\t%-2s\t%-4s\t%-4s\t%-3s\n", res[0], res[1], res[2], res[3], res[4], res[5], res[6], res[7], res[8], res[9], res[10], res[11]);
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
for (int i = 0 ; i < m ; i ++) {
if (strcmp(stu[i].province, str) == 0) {
flag = 0;
putchar('\n');
printf("%3d\t", stu[i].num);
printf("%6s\t", stu[i].name);
printf("%2s\t", stu[i].sex);
printf("%6s\t", stu[i].workplace);
printf("%6s\t", stu[i].province);
printf("%11s\t", stu[i].phonenum);
printf("%11s\t", stu[i].email);
printf("%18s\t", stu[i].idcard);
printf("%4s\t", stu[i].ifstay);
printf("%8s\t", stu[i].starttime);
printf("%8s\t", ppstu[i].back);
printf("%8s\t", ppstu[i].backtick);
printf("\n------------------------------------------------------------------------------------------------------------------------------------------------\n");
putchar('\n');
}
}
if (flag == 1) {
printf("\n\t\t||没有这个省份的人");
}
}
}
void sort() {
printf("\n\n\n");
printf("\t\t-------------------------------------------------\n");
printf("\t\t|| ---------------- ||\n");
printf("\t\t||**************参会信息管理系统***************||\n");
printf("\t\t|| ---------------- ||\n");
printf("\t\t|| 现在是排序界面 ||\n");
printf("\t\t||**************1,按照序号升序排序************||\n");
printf("\t\t||**************2,按照序号降序排序************||\n");
printf("\t\t||**************3,按照相同省份的排序**********||\n");
printf("\t\t||**************4,退出************************||\n");
printf("\t\t||*********************************************||\n");
int m = 0 ;
int l = 0 ;
struct nodes temp;
struct extra temps;
FILE *f, *e;
if ((f = fopen("student.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
}
while (!feof(f)) {
if (fread(&stu[m], sizeof(struct nodes), 1, f) == 1) {
m++;
}
}
if ((e = fopen("extra.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
}
while (!feof(e)) {
if (fread(&ppstu[l], sizeof(struct extra), 1, e) == 1) {
l++;
}
}
fclose(f);
fclose(e);
if (m == 0) {
printf("\n\t\t||文件没有内容");
}
int n ;
scanf("%d", &n);
if (n == 1) {
for (int i = 0 ; i < m - 1; i++) {
for (int j = 0 ; j < m - 1 - i ; j++) {
if (stu[j].num > stu[j + 1].num) {
temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = temp;
temps = ppstu[j];
ppstu[j] = ppstu[j + 1];
ppstu[j + 1] = temps;
}
}
}
printf("\n\t\t||升序排序结果展示");
putchar('\n');
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
printf("%-3s\t%-6s\t%-2s\t%-6s\t%-6s\t%-11s\t%-11s\t%-18s\t%-2s\t%-4s\t%-4s\t%-3s\n", res[0], res[1], res[2], res[3], res[4], res[5], res[6], res[7], res[8], res[9], res[10], res[11]);
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
for (int i = 0 ; i < m ; i++) {
printf("%-3d\t", stu[i].num);
printf("%-6s\t", stu[i].name);
printf("%-2s\t", stu[i].sex);
printf("%-6s\t", stu[i].workplace);
printf("%-6s\t", stu[i].province);
printf("%-11s\t", stu[i].phonenum);
printf("%-11s\t", stu[i].email);
printf("-%18s\t", stu[i].idcard);
printf("%-4s\t", stu[i].ifstay);
printf("%-8s\t", stu[i].starttime);
printf("%-8s\t", ppstu[i].back);
printf("%-8s\t", ppstu[i].backtick);
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
putchar('\n');
}
} else if (n == 2) {
for (int i = 0 ; i < m - 1; i++) {
for (int j = 0 ; j < m - 1 - i ; j++) {
if (stu[j].num < stu[j + 1].num) {
temp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = temp;
temps = ppstu[j];
ppstu[j] = ppstu[j + 1];
ppstu[j + 1] = temps;
}
}
}
printf("\n\t\t||升序排序结果展示");
putchar('\n');
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
printf("%-3s\t%-6s\t%-2s\t%-6s\t%-6s\t%-11s\t%-11s\t%-18s\t%-2s\t%-4s\t%-4s\t%-3s\n", res[0], res[1], res[2], res[3], res[4], res[5], res[6], res[7], res[8], res[9], res[10], res[11]);
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
for (int i = 0 ; i < m ; i++) {
printf("%-3d\t", stu[i].num);
printf("%-6s\t", stu[i].name);
printf("%-2s\t", stu[i].sex);
printf("%-6s\t", stu[i].workplace);
printf("%-6s\t", stu[i].province);
printf("%-11s\t", stu[i].phonenum);
printf("%-11s\t", stu[i].email);
printf("-%18s\t", stu[i].idcard);
printf("%-4s\t", stu[i].ifstay);
printf("%-8s\t", stu[i].starttime);
printf("%-8s\t", ppstu[i].back);
printf("%-8s\t", ppstu[i].backtick);
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
putchar('\n');
}
} else if (n == 3) {
FILE *f, *e;
int m = 0, t = 0;
if ((f = fopen("student.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
}
while (!feof(f)) {
if (fread(&stu[m], sizeof(struct nodes), 1, f) == 1) {
m++;
}
}
if ((e = fopen("extra.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
}
while (!feof(e)) {
if (fread(&ppstu[t], sizeof(struct extra), 1, e) == 1) {
t++;
}
}
putchar('\n');
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
printf("%-3s\t%-6s\t%-2s\t%-6s\t%-6s\t%-11s\t%-11s\t%-18s\t%-2s\t%-4s\t%-4s\t%-3s\n", res[0], res[1], res[2], res[3], res[4], res[5], res[6], res[7], res[8], res[9], res[10], res[11]);
printf("------------------------------------------------------------------------------------------------------------------------------------------------\n");
for (int j = 0 ; j < 29 ; j++) {
for (int i = 0 ; i < m ; i++ ) {
if (strcmp(stu[i].province, totprovince[j]) == 0) {
printf("%-3d\t", stu[i].num);
printf("%-6s\t", stu[i].name);
printf("%-2s\t", stu[i].sex);
printf("%-6s\t", stu[i].workplace);
printf("%-6s\t", stu[i].province);
printf("%-11s\t", stu[i].phonenum);
printf("%-11s\t", stu[i].email);
printf("%-18s\t", stu[i].idcard);
printf("%-4s\t", stu[i].ifstay);
printf("%-8s\t", stu[i].starttime);
printf("%-8s\t", ppstu[i].back);
printf("%-8s\t", ppstu[i].backtick);
printf("\n------------------------------------------------------------------------------------------------------------------------------------------------\n");
putchar('\n');
}
}
}
} else {
printf("\n\t\t||退出");
}
}
void re_move() {
print();
printf("\n\n\n");
printf("\t\t-------------------------------------------------\n");
printf("\t\t|| ---------------- ||\n");
printf("\t\t||**************参会信息管理系统***************||\n");
printf("\t\t|| ---------------- ||\n");
printf("\t\t|| 现在是删除界面 ||\n");
printf("\t\t||**************1,搜索序号删除****************||\n");
printf("\t\t||**************2,搜索姓名删除****************||\n");
printf("\t\t||*********************************************||\n");
printf("\t\t||**************4,退出************************||\n");
printf("\t\t||*********************************************||\n");
int n ;
scanf("%d", &n);
if (n == 1) {
int flag = 1;
int m = 0, c ;
FILE *f;
FILE *d;
if ((f = fopen("student.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
return;
}
while (!feof(f)) {
if (fread(&stu[m], sizeof(struct nodes), 1, f) == 1) {
m ++;
}
}
int t = 0;
if ((d = fopen("extra.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
}
while (!feof(d)) {
if (fread(&ppstu[t], sizeof(struct extra), 1, d) == 1) {
t++;
}
}
fclose(f);
fclose(d);
if (m == 0) {
printf("\n\t\t||文件中没有参会人员信息");
} else {
printf("\n\t\t||请输入你要删除的人的序号");
scanf("%d", &c);
for (int i = 0 ; i < m ; i ++) {
if (c == stu[i].num) {
flag = 0;
printf("\n\t\t||已经找到参会人员信息,是否删除(按y或者n)");
char ch[2];
scanf("%s", ch);
if (*ch == 'y') {
for (int j = i ; j < m ; j++) {
stu[j] = stu[j + 1];
ppstu[j] = ppstu[j + 1];
}
m--;
if ((f = fopen("student.txt", "wb")) == NULL) {
printf("\n\t\t||文件打开失败");
return;
}
if ((d = fopen("extra.txt", "wb")) == NULL) {
printf("\n\t\t||文件打开失败");
}
for (int j = 0 ; j < m ; j++) {
if (fwrite(&stu[j], sizeof(struct nodes), 1, f) != 1) {
printf("\n\t\t||不能保存");
getchar();
}
if (fwrite(&ppstu[j], sizeof(struct extra), 1, d) != 1) {
printf("\n\t\t||不能保存");
getchar();
}
}
fclose(f);
fclose(d);
printf("\n\t\t||删除成功");
break;
}
}
}
if (flag == 1) {
printf("\n\t\t||文件中不存在这个序号");
}
}
} else {
int m = 0;
char ch[6];
FILE *f, *d;
if ((f = fopen("student.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
return;
}
while (!feof(f)) {
if (fread(&stu[m], sizeof(struct nodes), 1, f) == 1) {
m ++;
}
}
int t = 0;
if ((d = fopen("extra.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
}
while (!feof(d)) {
if (fread(&ppstu[t], sizeof(struct extra), 1, d) == 1) {
t++;
}
}
if (m == 0) {
printf("\n\t\t||文件中没有参会人员信息");
} else {
int flag = 1;
printf("\n\t\t||请输入你要删除的人的姓名");
scanf("%s", ch);
for (int i = 0 ; i < m ; i ++) {
if (strcmp(ch, stu[i].name) == 0) {
printf("\n\t\t||已经找到参会人员信息,是否删除(按y或者n)");
char ch[2];
scanf("%s", ch);
if (*ch == 'y') {
flag = 0 ;
for (int j = i ; j < m ; j++) {
stu[j] = stu[j + 1];
}
m--;
if ((f = fopen("student.txt", "wb")) == NULL) {
printf("\n\t\t||文件打开失败");
return;
}
if ((d = fopen("extra.txt", "wb")) == NULL) {
printf("\n\t\t||文件打开失败");
}
for (int j = 0 ; j < m ; j++) {
if (fwrite(&stu[j], sizeof(struct nodes), 1, f) != 1) {
printf("\n\t\t||不能保存");
getchar();
}
if (fwrite(&ppstu[j], sizeof(struct extra), 1, d) != 1) {
printf("\n\t\t||不能保存");
getchar();
}
}
fclose(f);
fclose(d);
printf("\n\t\t||删除成功");
break;
}
}
}
if (flag == 1) {
printf("\n\t\t||文件中不存在这个名字");
}
}
}
}
void change() {
printf("\n\n\n");
printf("\t\t-------------------------------------------------\n");
printf("\t\t|| ---------------- ||\n");
printf("\t\t||**************参会信息管理系统***************||\n");
printf("\t\t|| ---------------- ||\n");
printf("\t\t|| 现在是排序界面 ||\n");
printf("\t\t||**************1,按照序号查找修改************||\n");
printf("\t\t||**************2,按照姓名查找修改************||\n");
printf("\t\t||*********************************************||\n");
printf("\t\t||***************按下别的键退出****************||\n");
printf("\t\t||*********************************************||\n");
int p ;
scanf("%d", &p);
if (p == 1) {
change01();
} else if (p == 2) {
change02();
} else {
printf("\n\t\t||退出");
}
}
void change01() {
void print();
int num;
FILE *fp, *d;
int m = 0, a;
int t = 0;
int i, j;
char name[10], sex[4], workplace[10], province[10], email[20], ifstay[3], startime[10];
char phonenum[20], idcard[20], back[20], backtick[20];
if ((fp = fopen("student.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
return;
}
if ((d = fopen("extra.txt", "rb")) == NULL) {
return;
}
while (!feof(fp)) {
if (fread(&stu[m], sizeof(struct nodes), 1, fp) == 1) {
m++;
}
}
while (!feof(d)) {
if (fread(&ppstu[t], sizeof(struct extra), 1, d) == 1) {
t++;
}
}
fclose(fp);
fclose(d);
if (m == 0) {
printf("\n\t\t||文件没有内容捏");
} else {
print();
printf("\n\t\t||输入你想修改的人的序号");
scanf("%d", &num);
}
for (i = 0; i < m; i++) {
if (num == stu[i].num) {
printf("\t\t-------------------------------------------------\n");
printf("\t\t|| ---------------- ||\n");
printf("\t\t||**************参会信息管理系统***************||\n");
printf("\t\t|| ---------------- ||\n");
printf("\t\t|| 现在是修改界面(选择你要修改的属性) ||\n");
printf("\t\t||**************1,序号************************||\n");
printf("\t\t||**************2,姓名************************||\n");
printf("\t\t||**************3,性别************************||\n");
printf("\t\t||**************4,单位************************||\n");
printf("\t\t||**************5,省份************************||\n");
printf("\t\t||**************6,邮箱************************||\n");
printf("\t\t||**************7,身份证号码******************||\n");
printf("\t\t||**************8,住宿************************||\n");
printf("\t\t||**************9,报到时间********************||\n");
printf("\t\t||**************10,报到时间*******************||\n");
printf("\t\t||**************11,返程时间*******************||\n");
printf("\t\t||**************12,是否订票*******************||\n");
printf("\t\t||*********************************************||\n");
scanf("%d", &a);
while (a) {
switch (a) {
case 1:
printf("\n\t\t||%d 修改为", num);
scanf("%d", &num);
stu[i].num = num;
for (j = i + 1; j < m; j++) {
if (stu[j].num == num) {
printf("修改成功\n");
getchar();
return;
}
}
break;
case 2:
printf("\n\t\t||将%d的名字修改为:", num);
scanf("%s", name);
strcpy(stu[i].name, name);
break;
case 3:
printf("\n\t\t||将%d的性别修改为:", num);
scanf("%s", sex);
strcpy(stu[i].sex, sex);
break;
case 4:
printf("\n\t\t||将%d的单位修改为:", num);
scanf("%s", workplace);
strcpy(stu[i].workplace, workplace);
break;
case 5:
printf("\n\t\t||将%d的省份修改为:", num);
scanf("%s", province);
strcpy(stu[i].province, province);
break;
case 6:
printf("\n\t\t||将%d的电话修改为:", num);
scanf("%s", phonenum);
strcpy(stu[i].phonenum, phonenum);
break;
case 7:
printf("\n\t\t||将%d的邮箱修改为:", num);
scanf("%s", email);
strcpy(stu[i].email, email);
break;
case 8:
printf("\n\t\t||将%d的身份证号修改为:", num);
scanf("%s", idcard);
strcpy(stu[i].idcard, idcard);
break;
case 9:
printf("\n\t\t||将%d的住宿修改为:", num);
scanf("%s", ifstay);
strcpy(stu[i].ifstay, ifstay);
break;
case 10:
printf("\n\t\t||将%d的报到时间修改为:", num);
scanf("%s", startime);
strcpy(stu[i].starttime, startime);
break;
case 11:
printf("\n\t\t||将%d的返程时间修改为:", num);
scanf("%s", back);
strcpy(ppstu[i].back, back);
break;
case 12:
printf("\n\t\t||将%d的是否订票修改为:", num);
scanf("%s", backtick);
strcpy(ppstu[i].backtick, backtick);
break;
default:
printf("\n\t\t||不存在这个操作");
break;
}
printf("\n\t\t是否继续:(想退出就按下0)");
scanf("%d", &a);
}
if ((fp = fopen("student.txt", "wb")) == NULL) {
printf("\n\t\t||文件打开失败");
return;
}
if ((d = fopen("extra.txt", "wb")) == NULL) {
printf("\n\t\t||文件打开失败");
return;
}
for (j = 0; j < m; j++) {
if (fwrite(&stu[j], sizeof(struct nodes), 1, fp) != 1) {
printf("\n\t\t||不能保存\n");
getchar();
}
if (fwrite(&ppstu[j], sizeof(struct extra), 1, d) != 1) {
return;
}
}
fclose(fp);
fclose(d);
printf("\n\t\t||修改成功!\n");
break;
}
}
if (m == i) {
printf("\n\t\t||找不到这个人员\n");
}
}
void change02() {
void print();
char str[40];
FILE *fp, *d;
int t = 0;
int m = 0, a;
int i, j;
char name[10], sex[4], workplace[10], province[10], email[20], ifstay[3], startime[10];
char phonenum[20], idcard[20], back[20], backtick[20];
if ((fp = fopen("student.txt", "rb")) == NULL) {
printf("\n\t\t||文件打开失败");
return;
}
if ((d = fopen("extra.txt", "rb")) == NULL) {
return;
}
while (!feof(fp)) {
if (fread(&stu[m], sizeof(struct nodes), 1, fp) == 1) {
m++;
}
}
while (!feof(d)) {
if (fread(&ppstu[t], sizeof(struct extra), 1, d) == 1) {
t++;
}
}
fclose(fp);
fclose(d);
if (m == 0) {
printf("\n\t\t||文件没有内容捏");
} else {
print();
printf("\n\t\t||输入你想修改的人的名字");
scanf("%s", str);
}
for (i = 0; i < m; i++) {
int num;
if (strcmp(stu[i].name, str) == 0) {
num = stu[i].num;
printf("\n\t\t||1序号,2名字,3性别,4单位,5省份,6电话,7邮箱,8身份证,9住宿,10报到时间 ,按下0键退出\n");
printf("\n\t\t||选择你要修改的属性");
scanf("%d", &a);
while (a) {
switch (a) {
case 1:
printf("\n\t\t||%d 修改为", num);
scanf("%d", &num);
stu[i].num = num;
for (j = i + 1; j < m; j++) {
if (stu[j].num == num) {
printf("修改成功\n");
getchar();
return;
}
}
break;
case 2:
printf("\n\t\t||将%d的名字修改为:", num);
scanf("%s", name);
strcpy(stu[i].name, name);
break;
case 3:
printf("\n\t\t||将%d的性别修改为:", num);
scanf("%s", sex);
strcpy(stu[i].sex, sex);
break;
case 4:
printf("\n\t\t||将%d的单位修改为:", num);
scanf("%s", workplace);
strcpy(stu[i].workplace, workplace);
break;
case 5:
printf("\n\t\t||将%d的省份修改为:", num);
scanf("%s", province);
strcpy(stu[i].province, province);
break;
case 6:
printf("\n\t\t||将%d的电话修改为:", num);
scanf("%s", phonenum);
strcpy(stu[i].phonenum, phonenum);
break;
case 7:
printf("\n\t\t||将%d的邮箱修改为:", num);
scanf("%s", email);
strcpy(stu[i].email, email);
break;
case 8:
printf("\n\t\t||将%d的身份证号修改为:", num);
scanf("%s", idcard);
strcpy(stu[i].idcard, idcard);
break;
case 9:
printf("\n\t\t||将%d的住宿修改为:", num);
scanf("%s", ifstay);
strcpy(stu[i].ifstay, ifstay);
break;
case 10:
printf("\n\t\t||将%d的报到时间修改为:", num);
scanf("%s", startime);
strcpy(stu[i].starttime, startime);
break;
case 11:
printf("\n\t\t||将%d的返程时间修改为:", num);
scanf("%s", back);
strcpy(ppstu[i].back, back);
break;
case 12:
printf("\n\t\t||将%d的是否订票修改为:", num);
scanf("%s", backtick);
strcpy(ppstu[i].backtick, backtick);
break;
default:
printf("\n\t\t||不存在这个操作");
break;
}
printf("\n\t\t是否继续:(想退出就按下0)");
scanf("%d", &a);
}
if ((fp = fopen("student.txt", "wb")) == NULL) {
printf("\n\t\t||文件打开失败");
return;
}
if ((d = fopen("extra.txt", "wb")) == NULL) {
printf("\n\t\t||文件打开失败");
return;
}
for (j = 0; j < m; j++) {
if (fwrite(&stu[j], sizeof(struct nodes), 1, fp) != 1) {
printf("\n\t\t||不能保存\n");
getchar();
}
if (fwrite(&ppstu[j], sizeof(struct extra), 1, d) != 1) {
return;
}
}
fclose(fp);
fclose(d);
printf("\n\t\t||修改成功!\n");
break;
}
}
if (m == i) {
printf("\n\t\t||找不到这个人员\n");
}
}