为了账号安全,请及时绑定邮箱和手机立即绑定

编程执行有问题

编程执行有问题

C
慕雪6341044 2017-06-16 10:54:51
#include<stdio.h> #include<string.h> #include<stdlib.h> int m, n; struct student { int num; char name[10]; char sex[5]; char class[10]; char major[10]; int dorm; }stu[1]; void input() { int i = 0; char t = 'y'; FILE *fp; fp = fopen("inform.txt", "w"); if (fp = NULL) { printf("error!\n"); exit(0); while (1) { printf("please enter student data:"); scanf("%d\n%d\n%s\n%c\n%s\n%s\n", &stu[i].num, &stu[i].dorm, &stu[i].name, &stu[i].sex, &stu[i].class,&stu[i].major); printf("是否继续输入(y/n)?: "); scanf("%c", &t); if (t == 'y' || t == 'Y') { i++; } } } fclose(fp); } void add() { int i = 0; char t = 'y'; FILE *fp; fp = fopen("inform.txt", "w"); if (fp = NULL) { printf("error!\n"); exit(0); while (1) { printf("please enter student data:"); scanf("%d\n%d\n%s\n%c\n%s\n%s\n", &stu[i].num, &stu[i].dorm, &stu[i].name, &stu[i].sex, &stu[i].class,&stu[i].major); printf("是否继续添加(y/n)?: "); scanf("%c", &t); if (t == 'y' || t == 'Y') { i++; } } } fclose(fp); } void del() { int i, num; char t = 'y'; FILE *fp, *fp1; printf("please enter del num:"); scanf("%d", &num); printf("%d\n%d\n%s\n%c\n%s\n%s\n", &stu[i].num, &stu[i].dorm, &stu[i].name, &stu[i].sex, &stu[i].class,&stu[i].major); for (n = i; n<m; n++) { stu[n] = stu[n + 1]; } printf("OK"); printf("是否继续删除(y/n)?: "); scanf("%c", &t); if (t == 'y' || t == 'Y') { i++; } fclose(fp); } void change() { FILE *fp; int num, i = 0; char t = 'y'; fp = fopen("inform.txt", "rb+"); while (t == 'y' || t == 'Y') { while (1) { printf("请输入修改的学号:"); scanf("%d", &num); if (num > 0) break; } while (!feof(fp)) { i = 0; fread(&stu[i], (long)sizeof(struct student), 1, fp); if (stu[i].num == num&&i == 0) { printf("你要修改的学生的信息:\n"); printf("%d\n%d\n%s\n%c\n%s\n%s\n", &stu[i].num, &stu[i].dorm, &stu[i].name, &stu[i].sex, &stu[i].class,&stu[i].major); i++; printf("你要修改的学生的信息:\n"); printf("please enter student data:"); scanf("%d\n%d\n%s\n%c\n%s\n%s\n", &stu[i].num, &stu[i].dorm, &stu[i].name, &stu[i].sex, &stu[i].class,&stu[i].major); fseek(fp, -(long)sizeof(struct student), 1); fwrite(&stu[i], (long)sizeof(struct student), 1, fp); fseek(fp, (long)sizeof(struct student), 1); } } printf("是否继续修改(y/n):"); scanf("%c", &t); if (t == 'y' || t == 'Y') { rewind(fp); i = 0; } } fclose(fp); } void search() { FILE *fp; int num,i=0; char t = 'y'; fp = fopen("inform.dat", "rb"); while (t == 'y' || t == 'Y') { while (1) { printf("请输入查询的学号:"); scanf("%d", &num); if (num > 0) break; } while (!feof(fp)) { fread(&stu[i], (long)sizeof(struct student), 1, fp); if (stu[i].num == num) { printf("%d\n%d\n%s\n%c\n%s\n%s\n", &stu[i].num, &stu[i].dorm, &stu[i].name, &stu[i].sex, &stu[i].class,&stu[i].major); break; } } printf("是否要继续查找(y/n):"); scanf("%c", &t); if (t == 'y' || t == 'Y') { rewind(fp); } fclose(fp); } } void off() { exit(0); } void main() { int ch; do { printf("         欢迎进入高校学生宿舍学生信息管理系统            \n"); printf("                                                          \n"); printf("                                                          \n"); printf("             请选择操作内容:                             \n"); printf("1输入                                                     \n"); printf("2添加                                                     \n"); printf("3删除                                                     \n"); printf("4修改                                                     \n"); printf("5查询                                                     \n"); printf("6退出                                                     \n"); printf("                                                          \n"); printf("please choice:(0-6):"); scanf("%d", &ch); switch (ch) { case 1:input(); break; case 2:add(); break; case 3:del(); break; case 4:change(); break; case 5:search(); break; case 6:off(); break; default:break; } } while (1); }
查看完整描述

2 回答

?
qq_莫非

TA贡献257条经验 获得超92个赞

说明代码里面还是有错

查看完整回答
反对 回复 2017-06-16
  • 2 回答
  • 1 关注
  • 1297 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信