This project is a Basic Calculator built in C, designed for beginners who are exploring the fundamentals of C programming. It demonstrates modular programming, file handling, and basic arithmetic operations. The project includes functionalities for arithmetic operations, history tracking (stored in a CSV file), and a menu-driven user interface. 🚀
• Arithmetic Operations:
• Addition ➕
• Subtraction ➖
• Multiplication ✖️
• Division ➗ (with zero division error handling)
• Square Root Calculation √
• Exponentiation a^b
• Matrix Addition 🧮
• History Tracking:
• Saves operation history in a data/history.csv file 📄
• Displays paginated history of operations for easy review 📜
• Menu-Driven Interface:
• User-friendly terminal interface for performing various tasks.
• Makefile Support:
• Simplified compilation process using a Makefile. 🛠️
basic-c-calculator/
├── build/ # Build output directory
│ └── calculator # Compiled executable
├── data/ # Data storage folder
│ └── history.csv # Stores calculation history
├── include/ # Header files
│ ├── basic_operations.h # Header for basic operations
│ ├── history.h # Header for history module
│ ├── matrix_operations.h # Header for matrix operations
│ ├── menu.h # Header for menu module
│ ├── operations.h # Header for advanced operations module
│ └── utils.h # Header for utility functions
├── src/ # Source code files
│ ├── app/ # Application-level code
│ │ ├── main.c # Main program entry
│ │ └── menu.c # Implements the main menu
│ ├── core/ # Core functional modules
│ │ ├── basic_operations.c # Performs basic operations (e.g., +, -, *, /)
│ │ ├── history.c # Handles operation history (save/load)
│ │ ├── matrix_operations.c # Handles matrix operations
│ │ ├── operations.c # Performs advanced mathematical operations
│ │ └── utils.c # Utility functions
├── .gitignore # Git ignore file
├── LICENSE # License file
├── Makefile # Build automation file
└── README.md # Documentation
git clone https://github.com/egecanakincioglu/basic-c-calculator.git
cd basic-c-calculator
Use the included Makefile to compile the project.
make
./build/calculator
Remove compiled files using:
make clean
• Menu Options:
• Perform arithmetic operations like addition, subtraction, etc.
• View operation history stored in data/history.csv.
• Exit the application safely while saving all data.
• Paginated History:
• Scroll through saved operation history with navigation options.
- Modular Programming: Code is divided into modules using
.hand.cfiles. - File Handling: Data recording and loading operations with
fopen,fclose,fprintf,fscanf. - Array and String Manipulation: Multidimensional arrays and string functions like
strcatandsprintf. - Dynamic Memory Management: Managing operation history using
mallocandfree. - Recursive Algorithms: Used in operations like determinant calculation.
- Basic Operations: Fundamental mathematical functions such as addition, subtraction, multiplication, and division.
- Advanced Operations: Square root and exponentiation.
- Matrix Operations: Matrix addition, multiplication, and determinant calculation.
- Error Detection:
- Division by zero check and user notification.
- Handling errors for square root of negative numbers.
- Error notifications for matrix dimension mismatch.
- Input Validation:
- Verifying that numerical inputs are positive and valid.
- Ensuring matrix dimensions are correct.
- Makefile Usage:
- Simplifying the build process with commands like
make,make clean, andmake run. - Optimized structure to compile only necessary changes in project files.
- Operation History Management:
- Storing operation history in a linked list structure.
- Saving and reloading operation history to/from a CSV file.
- Menu-Based Structure: Dynamically performing operations based on user input.
- Result Visualization: Clearly presenting results and operation history to the user after calculations.
- Modular structure to enhance code readability.
- Managing user errors and ensuring secure input validation.
- Optimizing memory usage with dynamic data management.
This project is an ideal application for practicing both basic and advanced C programming concepts. Its modular structure and functional design provide a practical experience in developing systems for real-world problems.
This project is licensed under the MIT License.
Enjoy coding! 🎉