This directory contains the C implementation of the Departmental Store Management System (DSMS).
- Project Overview
- Prerequisites
- Repository layout
- Quick start
- Makefile — build automation
- Build and run manually (without make)
- Cleaning build artifacts
- Debugging & development tips
- Adding a new source file
- Coding style & conventions
- Notes and troubleshooting
- License & author
This is a C-based departmental store management system. The code here is implemented in C source files (.c) with headers (.h). Build automation is done via a Makefile (recommended). The produced executable (by default) is dsms (can be changed in Makefile).
- A POSIX-like environment (Linux, macOS, WSL on Windows). Windows users can use MinGW/MSYS2 or WSL.
- C compiler (gcc or clang). Minimum recommended: gcc supporting C11.
- make (GNU Make) for using the Makefile (optional but recommended).
Optional:
- Any third-party libraries the project depends on (if any). If the project uses external libs, add them to
LDFLAGSin the Makefile.
This README focuses on the contents of:
DSMS/CUT/Code/DSMS/
Typical files:
*.c— C source files*.h— header filesMakefile— build rulesbin/— recommended output directory for executables (created by Makefile)README.md— this file
Adjust paths below if your sources are in subfolders.
- Open a terminal and navigate to the DSMS directory:
cd DSMS/CUT/Code/DSMS - Build using make:
This will produce the executable (default:
make
bin/dsms). - Run:
./bin/dsms
If make or the Makefile is unavailable, see the "Build manually" section.
A Makefile is recommended because it automates compilation, linking, cleaning, and debug builds.
Common targets:
makeormake all: Build the project (default).make run: Build then run the main executable.make debug: Build with debug flags (-g -O0) for use with a debugger.make clean: Remove object files and binaries.
Example:
# Build
make
# Build with debug symbols
make debug
# Run the app
make run
# Clean build artifacts
make clean- Create a file named
Makefilein this directory. - Paste the example Makefile below and save.
- Adjust variables:
TARGET— desired executable name.SRCDIR— path to your.cfiles (default.).CFLAGSandLDFLAGS— compiler and linker flags.
- Run
make.
Create a file named Makefile and paste the content below. This is a flexible template that discovers .c files in the source directory and produces the binary in bin/.
# Simple/portable Makefile for C projects
CC := gcc
SRCDIR := .
BINDIR := bin
TARGET := dsms
CFLAGS := -std=c11 -Wall -Wextra -O2
DEBUGFLAGS := -g -O0
LDFLAGS :=
SRCS := $(wildcard $(SRCDIR)/*.c)
OBJS := $(SRCS:.c=.o)
.PHONY: all clean debug run
all: $(BINDIR)/$(TARGET)
# Link
$(BINDIR)/$(TARGET): $(OBJS) | $(BINDIR)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS)
# Create bin directory if needed
$(BINDIR):
mkdir -p $(BINDIR)
# Compile .c -> .o
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
# Debug build (adds debug flags)
debug: CFLAGS += $(DEBUGFLAGS)
debug: clean all
# Run (builds first)
run: all
./$(BINDIR)/$(TARGET)
clean:
rm -f $(SRCDIR)/*.o $(BINDIR)/$(TARGET)Notes:
- Recipe lines must start with a TAB character (not spaces).
- If your project has subdirectories for sources, adjust
SRCS(e.g.,$(wildcard src/*.c src/modules/*.c)). - To link against libraries (e.g.,
-lm,-lncurses,-lsqlite3), add them toLDFLAGS, e.g.LDFLAGS := -lm -lsqlite3.
If you prefer a one-line compilation or don't have make:
Single file:
gcc -std=c11 -Wall -Wextra -O2 -o dsms main.c
./dsmsMultiple files:
gcc -std=c11 -Wall -Wextra -O2 -o dsms file1.c file2.c file3.c
./dsmsWith debug symbols:
gcc -std=c11 -Wall -Wextra -g -O0 -o dsms *.c
gdb ./dsmsIf you used the example Makefile:
make cleanManually:
rm -f *.o bin/dsms- Build with
make debugto include-gand disable optimizations for easier debugging. - Use
gdborlldb:gdb ./bin/dsms
- Use
valgrindto catch memory issues:valgrind --leak-check=full ./bin/dsms
- Add
-DDEBUGtoCFLAGS(or useDEBUGFLAGS) to enable debug-only code paths in your sources.
- Add the
.cand any.hfiles to the directory. - If using the example Makefile, it will automatically pick up
*.cfiles. - Re-run
make.
If your new source belongs in a subdirectory, update SRCS in the Makefile:
SRCS := $(wildcard src/*.c src/modules/*.c)- Prefer modularization: put declarations in header files (
.h) and definitions in source files (.c). - Use guards in headers:
#ifndef ITEM_H #define ITEM_H /* declarations */ #endif // ITEM_H
- Compile with warnings enabled (
-Wall -Wextra) and treat warnings seriously. - Use meaningful variable/function names and comment non-obvious logic.
- If
mkdir -pin the Makefile fails on native Windowscmd.exe, either create thebindirectory manually or run make inside an MSYS/MinGW or WSL shell which supportsmkdir -p. - If you need external libraries, install them and update
LDFLAGSand possiblyCFLAGS(include paths-I/path/to/include). - If compilation fails due to standards, try switching
-std=c11to-std=c99or remove the standard flag temporarily.
- Passionate about building smart, automated solutions for real-world problems.