新手求教,较简单的学生选课系统剩余两个问题不知道该怎么改
#include <stdio.h>#include<stdlib.h>
struct course
{
int num;
char name[15];
char xingzhi[10];
int ttime;
int score;
};
struct student
{
int snum;
int cnum;
}
/*insert*/
voidinsert()
{
void menu();
FILE *fp;
struct course c;
if((fp=fopen("course.txt","a+"))==NULL)
{
printf("cannot open file\n");
}
printf("\n\tInput course's information :\n");
printf("\tthe format is num name xingzhi ttime score:\n");
scanf("%d %s %s %d %d",&c.num,&c.name,&c.xingzhi, &c.ttime,&c.score);
fprintf(fp,"%d %s %s %d %d",c.num,c.name,c.xingzhi, c.ttime,c.score);
fclose(fp);
menu();
}
/*browse liu_lan*/
void browser()
{
void menu();
FILE *fp;
struct course c;
if((fp=fopen("course.txt","r"))==NULL)
{
printf("\nCannot open course!\n");
}
for(;!feof(fp);)
{
fscanf(fp,"%d%s%s%d%d",&c.num,&c.name,&c.xingzhi, &c.ttime,&c.score);
printf("%d %s %s %d %d",c.num,c.name,c.xingzhi, c.ttime,c.score);
} fclose(fp);
menu();
}
/*search*/
void search()
{
void menu();
FILE *fp;
struct course c;
int score;
printf("\ninput mark your wantto search:");
scanf("%d",&score);
if((fp=fopen("course.txt","r"))==NULL)
{
printf("\nCannot open course!\n");
}
for(;!feof(fp);)
{
fscanf(fp,"%d %s %s %d %d",&c.num,&c.name,&c.xingzhi,&c.ttime,&c.score);
if(c.mark==score)
printf("%d %s %s %d %d",c.num,c.name,c.xingzhi,c.ttime,c.score);
}
fclose(fp);
menu();
}
/*tong ji xuan ke ren shu*/
void xuanke_information()
{
void menu();
int total=0;
FILE *fp;
struct student c;
int num;
printf("\ninput course -number your wantto search:");
scanf("%d",&num);
if((fp=fopen("student.txt","r"))==NULL)
{
printf("\nCannot open student!\n");
}
for(;!feof(fp);)
{
fscanf(fp,"%d%d",&c.snum,&);
if()
{
total++;
printf("student_num=%d,course_num=%d",c.snum,);
}
}
fclose(fp);
printf("\n The number choose course_num %d is %d!",num,total); menu();
}
/*xuanke*/
void xuan_ke()
{
void menu();
int snum,cnum;
FILE *fp;
printf("\nPlease input your student_number and course number you want to choose:");
scanf("%d%d",&snum,&cnum);
if((fp=fopen("student.txt","a+"))==NULL)
{
printf("\nCannot open student!\n");
}
fprintf(fp,"%d %d",snum,cnum);
fclose(fp);
menu();
}
void menu()
{
int n,w=0;
printf("\n\t\t PLEASE ENTER A NUMBER FROM 0 TO 5!");
printf("\n\n\n\t*******************MENU**************************");
printf("\n\t\t 1 - insert informations");
printf("\n\t\t 2 - browers informations");
printf("\n\t\t 3 - search informations");
printf("\n\t\t 4 - xuan ke informations");
printf("\n\t\t 5- xuan ke ");
printf("\n\t\t 0 - Exit system");
printf("\n\n\n\t********************************************");
printf("\n\n\n\n\n\n\t\tChoose the number,please:");
scanf("%d",&n);
do
{
if(n>5||n<0)
{
printf("\nWrong! input again!");
scanf("%d",&n);
}
else w=1;
}
while(w==0);
switch(n)
{
case 1:insert();
break;
case 2:browser();
break;
case 3:search();
break;
case 4:xuan_ke();
break;
case 5:xuanke_information();
break;
case 0:exit(0);
}
}
main()
{
menu();
}