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

编程执行的时候有问题

编程执行的时候有问题

C
慕雪6341044 2017-06-11 11:24:17
查看完整描述

1 回答

?
望远

TA贡献1017条经验 获得超1032个赞

把代码贴出来看看,可能是在输入数据的时候没有&取地址符号。

查看完整回答
1 反对 回复 2017-06-11
  • 慕雪6341044
    慕雪6341044
    #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]
  • 慕雪6341044
    慕雪6341044
    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),
  • 慕雪6341044
    慕雪6341044
    &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() { char ch; do { printf(" 欢迎进入高校学生宿舍学生信息管理系统 \n"); printf(" \n"); printf(" \n"); printf("
点击展开后面4
  • 1 回答
  • 0 关注
  • 983 浏览

添加回答

举报

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