Employee Management System In C With Source Code
The Employee Management System In C is develop in C programming language, and This System In C is based on the concept to generate the Employee’s records and to add their records and update it. Here User can add their Employee’s details safely and it’s not time consuming.
A Employee Management System In C Language makes easy to store records of each and every employees. The whole project is designed in ‘C’ language and different variables and strings have been used for the development of this project. This mini project is easy to operate and understand by the users.
Watch the video here to see the full running of Employee Management System In C with Source Code.
This system project In also includes a downloadable Source Code In C Language, just find the downloadable source code below and click to start downloading.
To start creating a Employee Management System In C, make sure that you have code blocks or any platform of c language installed in your computer.
Steps on how to create a Employee Management System In C
Employee Management System In C With Source Code
- Step 1: Create a new project.
First open the code blocks IDE and click “create a new project“.
- Step 2: Choose console application.
Second click the “console application” and after that click “next“.
- Step 3: Choose C language.
Third choose “C language” and click “next“.
- Step 4: Name Your Project.
Fourth name the project you’ve created and click “next” after that click “finish“.
- Step 5: The actual code.
You are free to copy the given source code below or download the downloadable source code given.
The Code Given Below Is For The Log In Module
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
void login() { int a=0,i=0; char uname[10],c=' '; char pword[10],code[10]; char user[10]="user"; char pass[10]="pass"; do { printf("\n :::::::::::::::::::::::::: LOGIN FORM :::::::::::::::::::::::::: "); printf(" \n ENTER USERNAME:-"); scanf("%s", &uname); printf(" \n ENTER PASSWORD:-"); while(i<10) { pword[i]=getch(); c=pword[i]; if(c==13) break; else printf("*"); i++; } pword[i]='\0'; //char code=pword; i=0; //scanf("%s",&pword); if(strcmp(uname,"user")==0 && strcmp(pword,"pass")==0) { printf(" \n\n\n WELCOME TO EMPLOYEE RECORD MANAGEMENT SYSTEM !!!! LOGIN IS SUCCESSFUL"); printf("\n LOADING PLEASE WAIT... \n"); for(i=0; i<3; i++) { printf("."); Sleep(500); } printf("\n\n\n\t\t\t\tPress any key to continue..."); getch();//holds the screen break; } else { printf("\n SORRY !!!! LOGIN IS UNSUCESSFUL"); a++; getch();//holds the screen } } while(a<=2); if (a>2) { printf("\nSorry you have entered the wrong username and password for four times!!!"); getch(); } system("cls"); } |
In this module which is the log in page module of the system.
The Code Given Below Is For The Main Module
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
int main() { int i=0; login(); FILE *fp, *ft; /// file pointers char another, choice; /** structure that represent a employee */ struct emp { char name[40]; ///name of employee int age; /// age of employee char address[20];//address of employee float bs; /// basic salary of employee }; struct emp e; /// structure variable creation char empname[40]; /// string to store name of the employee long int recsize; /// size of each record of employee /** open the file in binary read and write mode * if the file EMP.DAT already exists then it open that file in read write mode * if the file doesn't exit it simply create a new copy */ fp = fopen("EMP.DAT","rb+"); if(fp == NULL) { fp = fopen("EMP.DAT","wb+"); if(fp == NULL) { printf("Connot open file"); exit(1); } } /// sizeo of each record i.e. size of structure variable e recsize = sizeof(e); /// infinite loop continues untile the break statement encounter while(1) { system("cls"); ///clear the console window printf(" \n :::::::::::::::::::::::::: |EMPLOYEES RECORD MANAGEMENT| :::::::::::::::::::::::::: \n"); gotoxy(30,05); /// move the cursor to postion 30, 10 from top-left corner printf("1> Add Employee's Records"); /// option for add record gotoxy(30,07); printf("2> List Employee's Records"); /// option for showing existing record gotoxy(30,9); printf("3> Modify Employee's Records"); /// option for editing record gotoxy(30,11); printf("4> Delete Employee's Records"); /// option for deleting record gotoxy(30,13); printf("5> Exit System"); /// exit from the program gotoxy(30,15); printf("Your Choice: "); /// enter the choice 1, 2, 3, 4, 5 fflush(stdin); /// flush the input buffer choice = getche(); /// get the input from keyboard switch(choice) { case '1': /// if user press 1 system("cls"); fseek(fp,0,SEEK_END); /// search the file and move cursor to end of the file /// here 0 indicates moving 0 distance from the end of the file another = 'y'; while(another == 'y') /// if user want to add another record { printf("\nEnter name: "); scanf("%s",e.name); printf("\nEnter age: "); scanf("%d", &e.age); printf("\nEnter Address:"); scanf("%s",e.address); printf("\nEnter basic salary: "); scanf("%f", &e.bs); fwrite(&e,recsize,1,fp); /// write the record in the file printf("\nAdd another record(y/n) "); fflush(stdin); another = getche(); } break; case '2': system("cls"); printf("EMPLOYEE's RECORD LIST (name, age, address, salary)"); rewind(fp); ///this moves file cursor to start of the file while(fread(&e,recsize,1,fp)==1) /// read the file and fetch the record one record per fetch { printf("\n\n%s \t\t%d \t%s \t%.2f",e.name,e.age,e.address,e.bs); /// print the name, age and basic salary } getch(); break; case '3': /// if user press 3 then do editing existing record system("cls"); another = 'y'; while(another == 'y') { printf("Enter the employee name to modify: "); scanf("%s", empname); rewind(fp); while(fread(&e,recsize,1,fp)==1) /// fetch all record from file { if(strcmp(e.name,empname) == 0) ///if entered name matches with that in file { printf("\nEnter new name,age,address and bs: "); scanf("%s%d%s%f",e.name,&e.age,&e.address,&e.bs); fseek(fp,-recsize,SEEK_CUR); /// move the cursor 1 step back from current position fwrite(&e,recsize,1,fp); /// override the record break; } } printf("\nModify another record(y/n)"); fflush(stdin); another = getche(); } break; case '4': system("cls"); another = 'y'; while(another == 'y') { printf("\nEnter name of employee to delete: "); scanf("%s",empname); ft = fopen("Temp.dat","wb"); /// create a intermediate file for temporary storage rewind(fp); /// move record to starting of file while(fread(&e,recsize,1,fp) == 1) /// read all records from file { if(strcmp(e.name,empname) != 0) /// if the entered record match { fwrite(&e,recsize,1,ft); /// move all records except the one that is to be deleted to temp file } } fclose(fp); fclose(ft); remove("EMP.DAT"); /// remove the orginal file rename("Temp.dat","EMP.DAT"); /// rename the temp file to original file name fp = fopen("EMP.DAT", "rb+"); printf("Delete another record(y/n)"); fflush(stdin); another = getche(); } break; case '5': fclose(fp); /// close the file exit(0); /// exit from the program } } return 0; } |
In this module which is the main module of the system.
Complete Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
#include <stdio.h> ///for input output functions like printf, scanf #include <stdlib.h> #include <conio.h> #include <windows.h> ///for windows related functions (not important) #include <string.h> ///string operations /** List of Global Variable */ COORD coord = {0,0}; /// top-left corner of window /** function : gotoxy @param input: x and y coordinates @param output: moves the cursor in specified position of console */ void gotoxy(int x,int y) { coord.X = x; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord); } /** Main function started */ void login() { int a=0,i=0; char uname[10],c=' '; char pword[10],code[10]; char user[10]="user"; char pass[10]="pass"; do { printf("\n :::::::::::::::::::::::::: LOGIN FORM :::::::::::::::::::::::::: "); printf(" \n ENTER USERNAME:-"); scanf("%s", &uname); printf(" \n ENTER PASSWORD:-"); while(i<10) { pword[i]=getch(); c=pword[i]; if(c==13) break; else printf("*"); i++; } pword[i]='\0'; //char code=pword; i=0; //scanf("%s",&pword); if(strcmp(uname,"user")==0 && strcmp(pword,"pass")==0) { printf(" \n\n\n WELCOME TO EMPLOYEE RECORD MANAGEMENT SYSTEM !!!! LOGIN IS SUCCESSFUL"); printf("\n LOADING PLEASE WAIT... \n"); for(i=0; i<3; i++) { printf("."); Sleep(500); } printf("\n\n\n\t\t\t\tPress any key to continue..."); getch();//holds the screen break; } else { printf("\n SORRY !!!! LOGIN IS UNSUCESSFUL"); a++; getch();//holds the screen } } while(a<=2); if (a>2) { printf("\nSorry you have entered the wrong username and password for four times!!!"); getch(); } system("cls"); } int main() { int i=0; login(); FILE *fp, *ft; /// file pointers char another, choice; /** structure that represent a employee */ struct emp { char name[40]; ///name of employee int age; /// age of employee char address[20];//address of employee float bs; /// basic salary of employee }; struct emp e; /// structure variable creation char empname[40]; /// string to store name of the employee long int recsize; /// size of each record of employee /** open the file in binary read and write mode * if the file EMP.DAT already exists then it open that file in read write mode * if the file doesn't exit it simply create a new copy */ fp = fopen("EMP.DAT","rb+"); if(fp == NULL) { fp = fopen("EMP.DAT","wb+"); if(fp == NULL) { printf("Connot open file"); exit(1); } } /// sizeo of each record i.e. size of structure variable e recsize = sizeof(e); /// infinite loop continues untile the break statement encounter while(1) { system("cls"); ///clear the console window printf(" \n :::::::::::::::::::::::::: |EMPLOYEES RECORD MANAGEMENT| :::::::::::::::::::::::::: \n"); gotoxy(30,05); /// move the cursor to postion 30, 10 from top-left corner printf("1> Add Employee's Records"); /// option for add record gotoxy(30,07); printf("2> List Employee's Records"); /// option for showing existing record gotoxy(30,9); printf("3> Modify Employee's Records"); /// option for editing record gotoxy(30,11); printf("4> Delete Employee's Records"); /// option for deleting record gotoxy(30,13); printf("5> Exit System"); /// exit from the program gotoxy(30,15); printf("Your Choice: "); /// enter the choice 1, 2, 3, 4, 5 fflush(stdin); /// flush the input buffer choice = getche(); /// get the input from keyboard switch(choice) { case '1': /// if user press 1 system("cls"); fseek(fp,0,SEEK_END); /// search the file and move cursor to end of the file /// here 0 indicates moving 0 distance from the end of the file another = 'y'; while(another == 'y') /// if user want to add another record { printf("\nEnter name: "); scanf("%s",e.name); printf("\nEnter age: "); scanf("%d", &e.age); printf("\nEnter Address:"); scanf("%s",e.address); printf("\nEnter basic salary: "); scanf("%f", &e.bs); fwrite(&e,recsize,1,fp); /// write the record in the file printf("\nAdd another record(y/n) "); fflush(stdin); another = getche(); } break; case '2': system("cls"); printf("EMPLOYEE's RECORD LIST (name, age, address, salary)"); rewind(fp); ///this moves file cursor to start of the file while(fread(&e,recsize,1,fp)==1) /// read the file and fetch the record one record per fetch { printf("\n\n%s \t\t%d \t%s \t%.2f",e.name,e.age,e.address,e.bs); /// print the name, age and basic salary } getch(); break; case '3': /// if user press 3 then do editing existing record system("cls"); another = 'y'; while(another == 'y') { printf("Enter the employee name to modify: "); scanf("%s", empname); rewind(fp); while(fread(&e,recsize,1,fp)==1) /// fetch all record from file { if(strcmp(e.name,empname) == 0) ///if entered name matches with that in file { printf("\nEnter new name,age,address and bs: "); scanf("%s%d%s%f",e.name,&e.age,&e.address,&e.bs); fseek(fp,-recsize,SEEK_CUR); /// move the cursor 1 step back from current position fwrite(&e,recsize,1,fp); /// override the record break; } } printf("\nModify another record(y/n)"); fflush(stdin); another = getche(); } break; case '4': system("cls"); another = 'y'; while(another == 'y') { printf("\nEnter name of employee to delete: "); scanf("%s",empname); ft = fopen("Temp.dat","wb"); /// create a intermediate file for temporary storage rewind(fp); /// move record to starting of file while(fread(&e,recsize,1,fp) == 1) /// read all records from file { if(strcmp(e.name,empname) != 0) /// if the entered record match { fwrite(&e,recsize,1,ft); /// move all records except the one that is to be deleted to temp file } } fclose(fp); fclose(ft); remove("EMP.DAT"); /// remove the orginal file rename("Temp.dat","EMP.DAT"); /// rename the temp file to original file name fp = fopen("EMP.DAT", "rb+"); printf("Delete another record(y/n)"); fflush(stdin); another = getche(); } break; case '5': fclose(fp); /// close the file exit(0); /// exit from the program } } return 0; } |
Run Quick Virus Scan for secure Download
Run Quick Scan for safe DownloadDownloadable Source Code
Summary
This System Project is being develop in C programming language, and this simple project can enhance the knowledge of the beginners or the students to develop their skills in programming, also this project is easy to understand the module and their variables.
Related Articles
- Simple Hospital Management System In C With Source Code
- Calendar In C Programming With Source Code
- Student Record System in C with Source Code
- Employee Management System Source Code using VB.Net
- Employee Management System Project in PHP With Source Code
Inquiries
If you have any questions or suggestions about Employee Management System In C , please feel free to leave a comment below.
Can you create a similar thing with multiple header files and to read data from a text file?