Database
Database
h>
#include <string.h>
#include <conio.h>
#include <windows.h>
/*
The code is a student management system written in the C programming language.
This program allows users to create, display, update, delete, and search for
student records.
It uses a struct to represent a student, and a binary file to store the student
records.
The program consists of a main function that displays a menu and calls the
appropriate functions depending on the user's input.
*/
// functions created to add, display, update, delete and search for students.
void createAccount();
void displayInfo();
void updateInfo();
void deleteInfo();
void searchInfo();
int main()
{
// option used in the switch case and while loop operations to create the menu
of the program
char option;
switch (option)
{
case '1':
createAccount();
break;
case '2':
displayInfo();
break;
case '3':
updateInfo();
break;
case '4':
deleteInfo();
break;
case '5':
searchInfo();
break;
case '0':
printf("\n\t\t\t====== Thank You ======");
break;
default:
printf("\n\t\t\tInvalid Option, Please Enter Right Option !\n");
}
}
return 0;
}
void createAccount()
{
FILE *fileOne = fopen("studentInfo.txt", "ab+");
if (fileOne == NULL)
{
printf("\n\t\t\tError !\n");
}
Student stundentInformation;
system("cls");
void displayInfo()
{
FILE *fileOne = fopen("studentInfo.txt", "rb");
if (fileOne == NULL)
{
printf("\n\t\t\tError !\n");
}
Student stundentInformation;
system("cls");
fclose(fileOne);
}
void updateInfo()
{
FILE *fileOne = fopen("studentInfo.txt", "rb");
FILE *temp = fopen("temp.txt", "wb");
system("cls");
fclose(fileOne);
fclose(temp);
remove("studentInfo.txt");
rename("temp.txt", "studentInfo.txt");
if (flag == 0)
{
printf("\n\t\t\tStudent Id is not found");
}
void deleteInfo()
{
FILE *fileOne = fopen("studentInfo.txt", "rb");
FILE *temp = fopen("temp.txt", "wb");
fclose(fileOne);
fclose(temp);
remove("studentInfo.txt");
rename("temp.txt", "studentInfo.txt");
if (flag == 0)
{
printf("\n\t\t\tStudent Id is not found");
}
void searchInfo()
{
FILE *fileOne = fopen("studentInfo.txt", "rb");
Student studentInformation;
if (fileOne == NULL)
{
printf("\n\t\t\tError !\n");
}
system("cls");
if (choice == 1)
{
system("cls");
printf("\t\t\t\t====== Search Student Information ======\n");
printf("\n\n\t\t\tEnter Student ID : ");
getchar();
gets(studentID);
while (fread(&studentInformation, sizeof(studentInformation), 1, fileOne)
== 1)
{
if (strcmp(studentInformation.studentId, studentID) == 0)
{
flag++;
printf("\n\t\t\tStudent Name : %s\n\t\t\tStudent ID : %s\n\t\t\
tStudent Grade : %s\n\t\t\tMother's name : %s\n\t\t\tStudent Contact No. : %s\n\t\
t\tSchool fee amount : %.2f\n", studentInformation.studentName,
studentInformation.studentId, studentInformation.studentGrade,
studentInformation.mothersName, studentInformation.fathersName,
studentInformation.studentContactNum, studentInformation.schoolFeeAmt);
}
}
if (flag == 0)
{
printf("\n\t\t\tStudent Id is not found");
}
}
else if (choice == 2)
{
system("cls");
printf("\t\t\t\t====== Search Student Information ======\n");
printf("\n\n\t\t\tEnter Student Grade. : ");
getchar();
gets(studentGrade);
printf("\n\n\t\t%-20s%-13s%-10s%-25s%-15s%-18s%-s\n", "Name", "ID",
"Grade", "Mother's name", "Father's name", "Contact", "School Fee anount");
printf("\t\
t----------------------------------------------------------------------------------
------");
while (fread(&studentInformation, sizeof(studentInformation), 1, fileOne)
== 1)
{
if (stricmp(studentInformation.studentGrade, studentGrade) == 0)
{
flag++;
printf("\n\n\t\t%-20s%-13s%-10s%-25s%-15s%-18s%-.2f",
studentInformation.studentName, studentInformation.studentId,
studentInformation.studentGrade, studentInformation.mothersName,
studentInformation.fathersName, studentInformation.studentContactNum,
studentInformation.schoolFeeAmt);
}
}
if (flag == 0)
{
printf("\n\t\t\tStudent Id is not found");
}
}
else
{
printf("\n\t\t\tInvalid Option");
}
fclose(fileOne);