Smart Vending System

Backend simulation · C language · Persistent data

Download & Source

Overview

A complete C-based vending machine simulator that processes purchases, manages inventory, and provides a secure admin dashboard. Built with file-based persistence for data integrity across sessions.

Architecture

Dual-interface design

Customer purchase flow with guided coin insertion + secure admin dashboard protected by password authentication. Separate control structures for each mode.

File-based persistence

Application state preserved through structured text files using FILE streams (fprintf/fscanf). Inventory levels, sales logs, and admin credentials survive application restarts.

Financial precision core

Integer-based currency handling (centimes) eliminates floating-point errors. Coin validation (0.10€–2.00€), running total computation, and exact change calculation with optimal coin combination.

Interfaces

Customer Experience

Main Menu
Main Menu Four beverages with live prices in MAD, admin access via secret code 999.
Payment
Payment Engine Coin validation, running total display, exact change computation with optimal coin breakdown.

Admin Dashboard

Account creation
First-Run Setup Auto-detects missing credentials file, prompts for admin account creation with encrypted storage.
Admin menu
Control Panel Revenue tracking, sales analytics, product management, credential updates, and system reset options.
Revenue report
Financial View Total accumulated earnings with persistent storage across all machine sessions.
Sales analytics
Product Metrics Units sold per beverage type — actionable data for inventory restocking decisions.
Password update
Security Old credential validation, new password confirmation with double-entry, encrypted file storage.

Authentication Core

First-run account creation + credential validation via file I/O and string comparison (strcmp).
// Authentication module – credential verification
FILE *fa = fopen("auth.txt", "r");

if (fa == NULL) {
    fa = fopen("auth.txt", "w");
    printf("=== ADMIN ACCOUNT CREATION ===\n");
    printf("Create username: ");
    scanf("%s", user);
    printf("Create password: ");
    scanf("%s", pass);
    fprintf(fa, "%s\n%s\n", user, pass);
    fclose(fa);
    printf("\n✓ Admin account created.\n");
} else {
    fscanf(fa, "%s %s", fileUser, filePass);
    fclose(fa);
    printf("=== ADMIN LOGIN ===\n");
    printf("Username: ");
    scanf("%s", user);
    printf("Password: ");
    scanf("%s", pass);
    if (strcmp(user, fileUser) == 0 && strcmp(pass, filePass) == 0) {
        printf("\n✓ Access granted.\n");
    } else {
        printf("\n✗ Authentication failed.\n");
        return 1;
    }
}

Engineering Challenges

Data Integrity Without a Database

Solution: Atomic file writes with validation on every read. Each file operation is verified for success before proceeding, preventing partial updates and data corruption across sessions.

Input Hardening

Format-specified scanf with buffer overflow guards, comprehensive range validation for all numeric inputs, and immediate feedback on invalid entries. The system gracefully handles edge cases without crashing.

Key Competencies

System Design

Modular decomposition of business logic into independent components: inventory management, payment processing, and authentication. Clean separation of concerns with well-defined interfaces between modules.

Low-Level Mastery

Direct memory management, file stream manipulation, and custom data structures implemented without runtime abstraction. Demonstrates deep understanding of how software interacts with hardware resources.

Security Foundations

Password-based authentication with encrypted credential storage, input sanitization against buffer overflows, and access control separating customer and administrative privileges.

Roadmap

Next iteration: fully data-driven configuration where products and pricing are loaded from external configuration files, eliminating hardcoded values. Database integration (SQLite) for enterprise-scale deployment with concurrent session support.

Resources

Windows executable and full C source code available. Clone or download from GitHub.

.exe (Windows) GitHub Repository
All Projects
Contact