A modular, command-line voting application written in C. This project demonstrates proper C project structure with separate compilation units, header files, and a professional build system.
- Cast Votes - Vote for one of 4 candidates (A, B, C, D)
- View Statistics - See total vote counts for each candidate (Admin only)
- Leading Candidate - Check which candidate is currently leading (Admin only)
- Password Protection - Admin functions protected with password authentication
- Cross-Platform - Works on Windows, Linux, and macOS
- Modular Architecture - Clean separation of concerns with multiple source files
- GCC (GNU Compiler Collection)
- Make (for building with Makefile)
- Git (for version control)
Linux (Ubuntu/Debian):
sudo apt update
sudo apt install build-essential gitmacOS:
xcode-select --installWindows:
voting-system/
├── src/
│ ├── main.c # Entry point and main menu loop
│ ├── voting.c # Voting and statistics functions
│ ├── admin.c # Admin authentication and menus
│ └── utils.c # Utility functions (display, clearing screen)
├── include/
│ ├── voting.h # Voting function declarations
│ ├── admin.h # Admin function declarations
│ └── utils.h # Utility function declarations
├── build/ # Compiled object files (auto-generated)
├── Makefile # Build configuration
├── README.md # This file
├── LICENSE # Project license
└── .gitignore # Git ignore rules
# Navigate to project directory
cd voting-system
# Build the project
make
# Run the program
make run
# Clean build artifacts
make clean
# View available commands
make helpgcc -Wall -Wextra -std=c99 -I./include -o voting_system src/main.c src/voting.c src/admin.c src/utils.cmingw32-make
mingw32-make run./voting_systemvoting_system.exemake runWhen you start the application, you'll see:
1. Cast a vote
2. View vote count (Admin only)
3. View leading candidate (Admin only)
4. Exit
- Select option 1 from main menu
- Choose a candidate (A, B, C, or D)
- Vote will be recorded
- Choose to cast another vote or return home
- Select option 2 or 3 from main menu
- Enter the admin password:
shadow - View statistics or leading candidate
- Return to home or exit
Password: shadow
The admin area allows you to:
- View detailed vote statistics for all candidates
- See which candidate is currently leading
- Track voting progress in real-time
- main.c - Program entry point and main loop
- voting.c - Core voting logic and statistics display
- admin.c - Authentication and admin menu handling
- utils.c - Shared utility functions
- Clean function declarations separated from implementation
- Prevents code duplication
- Easier to maintain and extend
- Makefile for easy compilation and management
- Automatic dependency tracking
- Clean separation of object files in
build/directory
- Warning Flags - Compiled with
-Wall -Wextra -Wpedanticfor strict error checking - Standard Compliance - Uses C99 standard for better compatibility
- Input Validation - Password buffer overflow protection
- Cross-Platform - Compatible with Windows, Linux, and macOS
| File | Purpose |
|---|---|
src/main.c |
Entry point, main menu loop, overall control flow |
src/voting.c |
Vote casting logic, statistics display, candidate ranking |
src/admin.c |
Authentication system, admin menu handling |
src/utils.c |
Screen clearing, menu printing, user input handling |
include/voting.h |
Vote-related function declarations and VoteCount struct |
include/admin.h |
Admin function declarations and constants |
include/utils.h |
Utility function declarations |
Makefile |
Build instructions and project compilation rules |
- Program starts → main.c runs
- Main menu displayed → via utils.c
- User selects option → main.c processes choice
- Voting/Admin functions → voting.c or admin.c handle logic
- Loop continues → until user exits
main.c ─┐
├─> gcc compiles to .o files ─> Linked together ─> voting_system
voting.c┤
admin.c ├─> (in build/ directory)
utils.c ┘
- GCC is not installed. See Requirements section above.
- Make is not installed. Install build-essential (Linux) or similar package.
- Ensure all files are in correct directories
- Check that header file paths in #include statements are correct
- Verify C99 support:
gcc --version
- This is normal on some systems. The program uses
clear(Linux/Mac) andcls(Windows) - Data is still being recorded correctly
Potential features for future versions:
- Save vote data to a file
- Reset/clear voting counts
- Multiple voting sessions
- Enhanced security (password hashing)
- Vote validation to prevent double voting
- Candidate name customization
- Different voting algorithms
To contribute to this project:
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the terms specified in the LICENSE file. See LICENSE for more details.
Original Developer: Avijit Roy
Updated: 07/07/2022
Refactored into Modular Project: 2024
If you encounter issues:
- Check the Troubleshooting section
- Verify all files are created correctly
- Ensure proper file permissions
- Check that your C compiler supports C99 standard
- Refactored into modular C project structure
- Separated code into multiple source files
- Added professional build system with Makefile
- Improved code quality and readability
- Cross-platform compatibility
- Enhanced error handling
- Better project documentation
Happy Voting! 🗳️