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.
Customer purchase flow with guided coin insertion + secure admin dashboard protected by password authentication. Separate control structures for each mode.
Application state preserved through structured text files using FILE streams (fprintf/fscanf). Inventory levels, sales logs, and admin credentials survive application restarts.
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.
// 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;
}
}
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.
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.
Modular decomposition of business logic into independent components: inventory management, payment processing, and authentication. Clean separation of concerns with well-defined interfaces between modules.
Direct memory management, file stream manipulation, and custom data structures implemented without runtime abstraction. Demonstrates deep understanding of how software interacts with hardware resources.
Password-based authentication with encrypted credential storage, input sanitization against buffer overflows, and access control separating customer and administrative privileges.
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.
Windows executable and full C source code available. Clone or download from GitHub.