Student Record System Source Code
Student Record System Source Code
SOURCE FILE
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
struct student{
char ID[15];
char name[20];
char add[20];
char parname[20];
int Class;
};
///This will set the forground color for printing in a console window.
WORD wColor;
///We will need this handle to get the current background attribute
CONSOLE_SCREEN_BUFFER_INFO csbi;
///We use csbi for the wAttributes word.
if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
///Mask out all but the background attribute, and add in the forgournd color
SetConsoleTextAttribute(hStdOut, wColor);
return;
DWORD count;
CONSOLE_SCREEN_BUFFER_INFO csbi;
SetConsoleTextAttribute(hStdOut, wColor);
if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
///This fills the buffer with a given character (in this case 32=space).
///This will set our cursor position for the next print statement.
SetConsoleCursorPosition(hStdOut, coord);
return;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
return;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
void drawRectangle(){
int i, j;
gotoxy(0,0);
printf("%c",201);
gotoxy(i, 0);
printf("%c",205);
gotoxy(78,0);
printf("%c",187);
for(i = 1; i < 25; i++){
gotoxy(78, i);
if(i == 6){
printf("%c",185);
}else{
printf("%c",186);
gotoxy(78, 25);
printf("%c",188);
gotoxy(i,25);
if(i == 35){
printf("%c",202);
}else{
printf("%c",205);
gotoxy(0,25);
printf("%c",200);
gotoxy(0,i);
if(i == 6){
printf("%c",204);
}else{
printf("%c",186);
gotoxy(i,6);
if(i == 35){
printf("%c",203);
}else{
printf("%c",205);
gotoxy(35,i);
printf("%c",186);
void clearWindow(){
int i,j;
gotoxy(i,j);printf(" ");
return;
void window(){
drawRectangle();
gotoxy(28,2);
SetColor(35);
gotoxy(20,3);
gotoxy(25,24);
SetColor(17);
SetColorAndBackground(31,28);
gotoxy(45,8);printf("SRS : %s",st);
SetColorAndBackground(17,15);
void add_student(){
clearWindow();
print_heading("Add Record");
FILE *fp;
fp = fopen("record.txt","ab+");
SetColor(45);
if(fp == NULL){
}else{
fflush(stdin);
gotoxy(print,10);printf("ID: ");gets(stu.ID);
gotoxy(print,14);printf("Address: ");gets(stu.add);
gotoxy(print,18);printf("Class: ");scanf("%d",&stu.Class);
SetColor(28);
fclose(fp);
return;
void search_student(){
clearWindow();
print_heading("Search Record");
SetColor(45);
char s_id[15];
int isFound = 0;
gets(s_id);
FILE *fp;
fp = fopen("record.txt","rb");
while(fread(&stu,sizeof(stu),1,fp) == 1){
if(strcmp(s_id,stu.ID) == 0){
isFound = 1;
break;
if(isFound == 1){
gotoxy(37,15);printf("Name: %s",stu.name);
gotoxy(37,16);printf("Address: %s",stu.add);
gotoxy(37,18);printf("Class: %d",stu.Class);
}else{
SetColor(28);
fclose(fp);
return;
void mod_student(){
clearWindow();
print_heading("Modify Record");
SetColor(45);
char s_id[15];
gets(s_id);
FILE *fp;
fp = fopen("record.txt","rb+");
fflush(stdin);
gotoxy(print,12);printf("ID: ");gets(stu.ID);
gotoxy(print,13);printf("Name: ");gets(stu.name);
gotoxy(print,14);printf("Address: ");gets(stu.add);
fseek(fp,-sizeof(stu), SEEK_CUR);
fwrite(&stu,sizeof(stu), 1, fp);
isFound = 1;
break;
if(!isFound){
fclose(fp);
SetColor(28);
return;
void delete_student(){
clearWindow();
print_heading("Delete Record");
SetColor(45);
char s_id[15];
gets(s_id);
fp = fopen("record.txt","rb");
fwrite(&stu,sizeof(stu),1,temp);
}
}
fclose(fp);
fclose(temp);
remove("record.txt");
rename("temp.txt","record.txt");
SetColor(28);
return;
void main_window(){
int choice;
SetColor(28);
int x = 2;
while(1){
gotoxy(x,16);printf("5. Exit");
scanf("%d",&choice);
switch(choice){
case 1:
add_student();
break;
case 2:
search_student();
break;
case 3:
mod_student();
break;
case 4:
delete_student();
break;
case 5:
exit(0);
break;
default:
break;
int main(){
ClearConsoleToColors(17,15);
window();
main_window();
return 0;