程序的目的是建立一个学生信息处理的程序,包括新建,浏览,和删除等操作,下面只有新建和浏览函数,但是调试时出现问题,请帮忙指教,谢谢拉
#include<stdio.h> #define size 20 struct student_type {char name[10]; int num; int math ; int eng;
}stu[size]; char filename[10];
int i; int j; char ch; FILE *fp; void new() { printf("please input the filename you want to give\n"); scanf("%s",filename); if ((fp=fopen("filename","w"))==NULL) {printf("cannot open the file\n"); return; } printf("please input the record\n"); for (i=0;i<size;i++) {printf ("the no.%d",i); printf("de jilu wei\n"); printf("xuehao"); scanf("%d",&stu[i].num) ; printf("name"); scanf("%s",stu[i].name); printf("math"); scanf("%d",&stu[i].math) ; printf("english"); scanf("%d",&stu[i].eng); ch= getchar(); printf("do you want to continue? y or n"); scanf("%c",&ch); if (ch=='n')break; }
for (j=0;j<i;j++) if( fwrite(&stu[j],sizeof(struct student_type),1,fp)!=1) printf("file write error\n");
fclose (fp) ; } void liulan() {printf("please input the name you want to liulan"); scanf("%s",filename); fp=fopen("filename","r"); for (i=0;;i++) fread(&stu[i],sizeof(struct student_type),1,fp) ; for (j=0;j<i;j++) printf("%d\n%s\n%d\n%d\n",stu[j].num,stu[j].name,stu[j].math,stu[j].eng);
fclose (fp); } main() { int i; clrscr();
for(i=0;i<=20;i++) printf(" "); printf("welcome to the student management system\n"); printf("please input the bianhao which you want to do\n"); printf(" 1.new\n"); printf(" 2.tianjia\n") ; printf(" 3.shanchu\n"); printf(" 4.chaxun\n"); printf(" 5.paixu\n"); printf(" 6.liulan\n") ; scanf("%d",&i); switch(i) {case 1:new(); break; / * case 2:tianjia(); break; case 3:shanchu();break; case 4:chaxun();break; case 5:paixu();break; */ case 6:liulan();break; }