100% found this document useful (1 vote)
376 views

C Program of Student Database System

This C program implements a student database system that allows the user to store, search, and retrieve student records. The program uses a struct to define student records with fields for roll number, first name, last name, and mark. It provides a menu for the user to choose between adding a new record, searching by student name, searching by roll number, or quitting. New records are appended to a text file. Searches compare the search term to student data read from the file. Matches are printed with the full student record details.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
376 views

C Program of Student Database System

This C program implements a student database system that allows the user to store, search, and retrieve student records. The program uses a struct to define student records with fields for roll number, first name, last name, and mark. It provides a menu for the user to choose between adding a new record, searching by student name, searching by roll number, or quitting. New records are appended to a text file. Searches compare the search term to student data read from the file. Matches are printed with the full student record details.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

C Program of Student Database System #include<stdio.h> #include<string.h> #include<stdlib.

h> struct { int roll_no; char firstname[20]; char lastname[[20]; int mark; }student; int main(); { int flag, choice, shift, rollnumber, found, continu, length; char studentname[20]; FILE *fp; printf("....................\n"); print("........made by Gobinda.........\n"); printf("....................\n"); printf("\n\t C PROGRAM OF STUDENT DATABASE SYSTEM"); Label1: printf("\n1->Store a new record in database\n"); printf("2->Search a student record by Student First Name\n"); printf("3->Search a student record by Roll No\n"); printf("4->Quit Student Database"); printf("\n\n"); printf("Enter Your Choice: "); scanf("%d", &choice); switch(choice) { case1: Label2: printf("\nEnter Student Details: \n\nRoll Number(Integer):"); scanf("%d", &student, roll_no); printf("\nName:"); scanf("%s", &student, firstname); printf("\nSurname:"); scanf("%s", &student, lastname); printf("\nMark(0-100 integer):"); scanf("("%s", &student, mark");

fp=fopen("studentfile.txt", "a+"); fprint(fp,"\n%d\t%s\t%s\t%d\t", student.roll_no, student.firstname, student.lastname, student.mark); fclose(fp); printf("A student record has been added successfully...\n"); printf("\n\n1->Wish to add another record in database"); printf("\n2->Wish to move to Main Menu"); printf("\n3->Exit from Program\n"); scanf("%d", &shift); if(shift==1) goto Label2; if(shift==2) goto Label1; if(shift==3) break; if(shift!=1&&2&&3){ printf("Exiting....."); break; } case2: Label4: printf("\nEnter student first name:"); scanf("%s", &studentname); printf("Searching record with studentname=%s.\n", studentname); found=0; if((fp=fopen("studentfile.txt", "r"))==NULL) { printf("\The file is empty...\n\n"); } else { while(!feof(fp)&& found==0) { fscanf(fp,"\n%d\t%s\t%s\t%d\t", student.roll_no, student.firstname, student.lastname, student.mark); length=strlen(student.firstname); if(student.firstname[length]==studentname[length]) found=1; } } if(found) {

printf("\nThe record is found."); printf("\nRoll No:%d\nName:%s\nSurname:%s\nMark:%d\n", student.roll_no, student.firstname, student.lastname, student.mark); } else { printf("Not found...\n"); getch(); } Label5: printf("\n\n1->Wish to search another record"); printf("\n2->Wish to move to Main Menu"); printf("\n3->Exit from Program\n"); scanf("%d", &shift); if(shift==1) goto Label4; if(shift==2) goto Label1; if(shift==3) break; if(shift!=1&&2&&3){ printf(\nEnter a valid choice); goto Label5; } Case3: Label6: printf(\nEnter the Roll Number:); scanf(%d, &rollnumber); printf(Searching record with rollnumber=%d.\n, rollnumber); found=0; if((fp=fopen("studentfile.txt", "r"))==NULL) { Printf(!The file is empty\n\n); } else { while(!feof(fp)&t found==0) { fscanf(fp,"\n%d\t%s\t%s\t%d\t", &student.roll_no,& student.firstname,& student.lastname, &student.mark); if(student.roll_no==rollnumber) found=1;

} } If (found) { Printf(\The record is found.); printf("\nRoll No:%d\nName:%s\nSurname:%s\nMark:%d\n", student.roll_no, student.firstname, student.lastname, student.mark); } else { Printf(Not found\n); getch(); } Label7: printf(\n\n1->Wish to search more); printf(\n2->Wish to move to Main Menu); printf(\n3->Exit from Program\n); scanf(%d%, &shift); if(shift==1) goto Label6; if(shift==2) goto Label1; if(shift==3) break; if(shift!=1&&2&&3){ printf(Enter a valid choice); goto Label7: } case4: berak; default: primntf(Bad ChoiceEnter the choice again\n); goto Label1: } getch(); return 0; }

You might also like