Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
738 views
in Computer by (69.8k points)

Write a program that reads the following information from the keyboard – student_id, student name and total marks and writer to a file. After taking the information it closes the file and displays the information about the student whose student_id has been entered by the user. 

1 Answer

+1 vote
by (69.2k points)
selected by
 
Best answer

//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----------------------------");

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...