Skip to content

Latest commit

Β 

History

History
80 lines (59 loc) Β· 1.6 KB

File metadata and controls

80 lines (59 loc) Β· 1.6 KB

Calculator

A simple calculator written in C that supports basic arithmetic operations, parentheses, decimal numbers, and negative numbers.

Features

  • Supports addition (+), subtraction (-), multiplication (x), and division (/).
  • Handles parentheses for operation precedence.
  • Supports decimal numbers and negative numbers.

Compilation

make re

Usage

Run the calculator with an expression as an argument:

./calculator "expression"

Examples

./calculator "3.2+5"
Result = 8.200000
./calculator "5x(8-3)"
Result = 25.000000
./calculator "-5x(8-3)"
Result = -25.000000

Available Commands

Build Commands

  • make all or make: Compile the project.
  • make re: Clean and rebuild everything.
  • make clean: Remove object files and temporary files.
  • make fclean: Remove compiled binaries and clean files.
  • make debug: Compile with debugging flags (-ggdb3).

Source Files

The project is structured as follows:

πŸ“‚ src
β”œβ”€β”€ πŸ“„ main.c
β”œβ”€β”€ πŸ“„ operation.c
β”œβ”€β”€ πŸ“„ parentheses.c
β”‚
β”œβ”€β”€ πŸ“‚ expression
β”‚   β”œβ”€β”€ πŸ“„ evaluator.c
β”‚   β”œβ”€β”€ πŸ“„ parser.c
β”‚   β”œβ”€β”€ πŸ“„ part.c
β”‚
β”œβ”€β”€ πŸ“‚ utils
β”‚   β”œβ”€β”€ πŸ“„ list.c
β”‚   β”œβ”€β”€ πŸ“„ delete_char.c
β”‚   β”œβ”€β”€ πŸ“„ is_digit.c
β”‚   β”œβ”€β”€ πŸ“„ strtod.c

Compilation Flags

  • CFLAGS: -W -Wall -Wextra -O1 (Enables warnings for better code quality).
  • CPPFLAGS: -I./include (Includes the header files from the include/ directory).

Author