//display records on the basis of student id entered.
int first_ch;
clrscr();
heading();
printf("\n\n\n\t\t\t\t MENU");
printf("\n\n\n\t\t1.Create a new database.");
printf("\n\n\t\t2.Continue with the existing database.");
printf("\n\n\t\t3. Exit.");
printf("\n\n\n\t\tEnter your choice( 1 - 3): ");
scanf("%d",&first_ch);
switch(first_ch)
{
case 1:
create();
break;
case 2:
menu();
break;
exit();
break;
default:
printf("\n\n\n\t\tYou have entered wrong choice...!!!..The program will exit now.");
printf("\n\n\n\n\tEnter the Employee Records :\n ");
printf("\n\n\t\t Student id : ");
fflush(stdin); scanf("%d",&s[i].stu_id);
printf("\n\n\t\t Name : ");
fflush(stdin); scanf("%s",&s[i].stu_name);
printf("\n\n\t\t Total Marks : ");
fflush(stdin); scanf("%d",&s[i].marks);
fwrite(&s,sizeof(s[i]),1,fp);
printf("\n\n\n\t\tDo you wish to enter more records
(y/n) ?");
ch=getch();
}
printf("\n\n\n\t%d Records have been written in the file.",ctr);
fclose(fp);
menu();
}
void menu()
{
char ch;
clrscr();
heading();
printf("\n\n\n\t\t\t MENU :-");
printf("\n\n\t\t1.To DISPLAY all the records");
printf("\n\n\t\t2.To SEARCH a record");
printf("\n\n\t\t3.EXIT");
printf("\n\n\n\t\tEnter your choice (1 - 3) : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
display();
break;
case 2:
search();
break;
case 3:
exit();
break;
default:
printf("\n\n\tYou have entered a WRONG
CHOICE..!!..Please Re-enter your
choice");
menu();
}
}
void display()
fp=fopen("student.c","r");
rewind(fp);
while(fread(&s,sizeof(s[i]),1,fp)==1)
{
ctr++;
clrscr();
heading();
printf("\n\n\n\tFollowing are the details :-");
printf("\n\n\tRecord #%d",ctr);
printf("\n\n\t\tStudent id : %d",s[i].stu_id);
printf("\n\n\t\t Name : %s",s[i].stu_name);
printf("\n\n\t\tTotal Marks: %d",s[i].marks);
printf("\n\n\n\n\t\tPlease Press Enter...");
getch();
}
menu();
}
void search()
{
int f,flag=0;
char ch='y';
while(ch=='y')
{
clrscr();
flag=0;
heading();
printf("\n\n\n\tEnter the Student id to be searched : ");
fflush(stdin);
scanf("%d",&b.stu_id);
fp=fopen("student.c","r");
rewind(fp);
while(fread(&s,sizeof(s[i]),1,fp)==1)
{
if(s[i].stu_id == b.stu_id)
clrscr();
flag=1;
heading();
printf("\n\n\n\tThe details of the record
having Student id %d are :-
",b.stu_id);
disp();
}
}
fcloseall();
if(flag==0)
printf("\n\n\n\t\tNo Match found !!");
printf("\n\n\n\tDo u wish to search for more records (y/n) ?
");
ch=getch();
}
menu();
void heading()
{
printf("\n\n\t\t\tSTUDENT DATABASE MANAGEMENT");
printf("\n\n\t\t\t----------------------------");
}