C Basics ▶
1. Introduction to C
2. History & Features
3. Installation & Setup
4. Structure of C Program
5. Data Types
6. Variables
7. Constants
8. Operators
9. Input & Output
10. Control Statements
11. Loops
12. Break & Continue
13. Arrays
14. Strings
15. Functions
Pointers & Memory ▶
16. Pointers Basics
17. Pointer Arithmetic
18. Arrays & Pointers
19. Pointers to Functions
20. Dynamic Memory Allocation
21. malloc & calloc
22. realloc & free
23. Memory Leaks
24. 2D Arrays & Pointers
25. Pointer Mini Project
Structures, Unions & Files ▶
26. Structures
27. Nested Structures
28. Unions
29. Enums
30. typedef
31. File Handling Basics
32. File Operations
33. Reading & Writing Files
34. Binary Files
35. File Handling Project
Data Structures & Algorithms ▶
36. Introduction to DSA
37. Linked Lists
38. Stacks
39. Queues
40. Trees
41. Binary Search Tree
42. Sorting Algorithms
43. Searching Algorithms
44. Graph Basics
45. DSA Mini Project
Advanced C & Projects ▶
C Capstone Project – Employee Management System
This is the final lesson of the C Programming course.
In this lesson, we build a complete working project using C, exactly the way it is done in real applications.
Project Overview
We will build a Console-Based Employee Management System.
This project uses:
- Structures
- Functions
- File handling
- Menu-driven logic
- Real-world data storage
What This Project Can Do
- Add employee records
- View all employees
- Search employee by ID
- Store data permanently in a file
Complete Program Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Employee {
int id;
char name[50];
char department[30];
float salary;
};
void addEmployee();
void viewEmployees();
void searchEmployee();
int main() {
int choice;
while (1) {
printf("\n===== Employee Management System =====\n");
printf("1. Add Employee\n");
printf("2. View All Employees\n");
printf("3. Search Employee by ID\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addEmployee();
break;
case 2:
viewEmployees();
break;
case 3:
searchEmployee();
break;
case 4:
printf("Exiting program...\n");
exit(0);
default:
printf("Invalid choice. Try again.\n");
}
}
}
Explanation of the Code
struct Employee groups employee data such as ID, name, department and salary.
The program uses a menu-driven infinite loop so the user can perform multiple operations without restarting the program.
Add Employee Function
void addEmployee() {
struct Employee emp;
FILE *fp = fopen("employees.dat", "ab");
if (fp == NULL) {
printf("File error\n");
return;
}
printf("Enter Employee ID: ");
scanf("%d", &emp.id);
printf("Enter Name: ");
scanf(" %[^\n]", emp.name);
printf("Enter Department: ");
scanf(" %[^\n]", emp.department);
printf("Enter Salary: ");
scanf("%f", &emp.salary);
fwrite(&emp, sizeof(emp), 1, fp);
fclose(fp);
printf("Employee added successfully.\n");
}
This function writes employee data into a binary file using fwrite().
View Employees Function
void viewEmployees() {
struct Employee emp;
FILE *fp = fopen("employees.dat", "rb");
if (fp == NULL) {
printf("No records found.\n");
return;
}
while (fread(&emp, sizeof(emp), 1, fp)) {
printf("\nID: %d", emp.id);
printf("\nName: %s", emp.name);
printf("\nDepartment: %s", emp.department);
printf("\nSalary: %.2f\n", emp.salary);
}
fclose(fp);
}
This function reads all employee records from the file and displays them.
Search Employee Function
void searchEmployee() {
struct Employee emp;
FILE *fp = fopen("employees.dat", "rb");
int id, found = 0;
if (fp == NULL) {
printf("File not found.\n");
return;
}
printf("Enter Employee ID to search: ");
scanf("%d", &id);
while (fread(&emp, sizeof(emp), 1, fp)) {
if (emp.id == id) {
printf("\nEmployee Found!");
printf("\nName: %s", emp.name);
printf("\nDepartment: %s", emp.department);
printf("\nSalary: %.2f\n", emp.salary);
found = 1;
break;
}
}
if (!found)
printf("Employee not found.\n");
fclose(fp);
}
Sample Output
===== Employee Management System =====
1. Add Employee
2. View All Employees
3. Search Employee by ID
4. Exit
Enter your choice: 1
Enter Employee ID: 101
Enter Name: John
Enter Department: IT
Enter Salary: 55000
Employee added successfully.
Mini Practice
- Add update and delete employee options
- Sort employees by salary
- Export data to text file
Final Note
If you understand and can modify this project, you are ready for real-world C programming.
Well done on completing the C Programming course.