C Program of Student Database System
C Program of Student Database System
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; }