We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/*程序有bug,测试请见谅 1. 创建第一个节点必须学号为一 2. 删除|插入时如果输入不存在的列会报错 3. 删除时不能删除第一个输入的数据 */ #include<stdio.h> #include<stdlib.h> #include<windows.h> typedef struct Student_Info{//定义结构体 char name[20]; int num; int age; char sex; int Dorm_Num; int Bed_Num; struct Student_Info *next; }Stu; int main(){ system("title Student_Info_Manager"); Stu *p_tail = (Stu *)malloc(sizeof(Stu)); Stu *p_head = (Stu *)malloc(sizeof(Stu)); Stu *create(Stu *,Stu *); void print(Stu *); int search(Stu *); Stu *insert(Stu *); int delect(Stu *p_head); void save(Stu *); void jundge(Stu *p_head); p_head = create(p_head,p_tail); print(p_head); search(p_head); insert(p_head); delect(p_head); save(p_head); jundge(p_head); return 1; } Stu *create(Stu *p_head,Stu *p_tail) { int count = 0,i = 0; printf("输入创建的学生信息数:"); scanf("%d",&count); for(i = 0;i < count;i ++) { Stu *p; p = (Stu *)malloc(sizeof(Stu)); printf("请输入第%d个学生的信息(姓名 年龄 编号 性别 寝室号 床号)\n",i+1); scanf("%s %d %d %c %d %d",&p->name,&p->age,&p->num,&p->sex,&p->Dorm_Num,&p->Bed_Num); p->next = NULL; if(p->num == 1) { p_head = p; p_tail = p; } else { p_tail->next = p; p_tail = p; } } return p_head; } void print(Stu *p_head) { Stu *p = p_head; if(!p) { printf("数据为空"); exit(0); } while(p) { printf("该学生姓名:%s 年龄:%d 学号:%d 性别:%c 宿舍号:%d 床号:%d\n",p->name,p->age,p->num,p->sex,p->Dorm_Num,p->Bed_Num); p = p->next; } } int search(Stu *p_head) { int a; Stu *p = p_head; printf("请输入要查询的学号:"); scanf("%d",&a); while(p) { if(p->num == a) { printf("该学生姓名:%s 年龄:%d 学号:%d 性别:%c 宿舍号:%d 床号:%d\n",p->name,p->age,p->num,p->sex,p->Dorm_Num,p->Bed_Num); return 0; } else p = p->next; } printf("查无此人!\n"); } Stu *insert(Stu *p_head) { Stu *p_new = (Stu *)malloc(sizeof(Stu)); Stu *p = (Stu *)malloc(sizeof(Stu)); int a = 0; printf("请输入插入位置:"); scanf("%d",&a); printf("请输入学生信息(姓名 年龄 编号 性别 寝室号 床号)\n"); scanf("%s %d %d %c %d %d",&p_new->name,&p_new->age,&p_new->num,&p_new->sex,&p_new->Dorm_Num,&p_new->Bed_Num); p = p_head; while(p) { if(p->num == a) { p_new->next = p->next; p->next = p_new; break; } else p = p->next; } print(p_head); } int delect(Stu *p_head) { int a; Stu *p = (Stu *)malloc(sizeof(Stu)); Stu *p_del = (Stu *)malloc(sizeof(Stu)); printf("请输入删除的学号:"); scanf("%d",&a); p = p_head; while(p) { if(p->next->num == a) { p_del = p->next; p->next = p_del->next; free(p_del); print(p_head); return 2; } else p = p->next; } printf("查无此人!\n"); } void save(Stu *p_head) { printf("现在开始向文件输入内容\n"); FILE *fp; Stu *p = (Stu *)malloc(sizeof(Stu)); p = p_head; fp=fopen("a.txt","w"); while(p!=NULL) { if(fprintf(fp,"该学生姓名:%s 年龄:%d 学号:%d 性别:%c 宿舍号:%d 床号:%d\n",p->name,p->age,p->num,p->sex,p->Dorm_Num,p->Bed_Num)>=0) p = p->next; else printf("输入失败"); } printf("输入完成!\n"); fclose(fp); } void jundge(Stu *p_head) { printf("现在开始从文件输出内容\n"); FILE *fp; Stu *p = (Stu *)malloc(sizeof(Stu)); p = p_head; fp=fopen("a.txt","r"); if(fp==NULL) { printf("Open the file fail!!!"); exit(5); } else { printf("1"); while(!feof(fp)) { fscanf(fp,"该学生姓名:%s 年龄:%d 学号:%d 性别:%c 宿舍号:%d 床号:%d\n",p->name,&p->age,&p->num,&p->sex,&p->Dorm_Num,&p->Bed_Num); printf("该学生姓名:%s 年龄:%d 学号:%d 性别:%c 宿舍号:%d 床号:%d\n",p->name,p->age,p->num,p->sex,p->Dorm_Num,p->Bed_Num); p = p->next; } } fclose(fp); print(p_head); }
The text was updated successfully, but these errors were encountered:
革命尚未成功:smile:
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: