C Mini Projects
Intermediate projects to enhance your C programming skills
⚡ Welcome to Mini Projects
Advance your C skills with intermediate projects featuring arrays, structures, file handling, and algorithms that bridge basic concepts with real applications.
Mini Project Categories
Management Systems
Data organization and management
Console Games
Interactive gaming applications
Algorithms
Sorting and searching implementations
File Operations
File handling and data persistence
🔹 Project 1: Student Management System
A student management system teaches structured data organization using structs and arrays for building practical database-like applications in C. Create structures storing student information like ID, name, grades, and contact details. Implement functions for adding, updating, searching, and displaying student records. Develop a menu interface for database operations and data persistence using file I/O. This project demonstrates real-world data management principles. It combines structures, arrays, functions, and file operations into one comprehensive application.
#include <stdio.h>
#include <string.h>
struct Student {
int id;
char name[50];
float marks[3];
float average;
char grade;
};
void calculateGrade(struct Student *s) {
s->average = (s->marks[0] + s->marks[1] + s->marks[2]) / 3;
if(s->average >= 90) s->grade = 'A';
else if(s->average >= 80) s->grade = 'B';
else if(s->average >= 70) s->grade = 'C';
else if(s->average >= 60) s->grade = 'D';
else s->grade = 'F';
}
void displayStudent(struct Student s) {
printf("\n--- Student Details ---\n");
printf("ID: %d\n", s.id);
printf("Name: %s\n", s.name);
printf("Marks: %.1f, %.1f, %.1f\n", s.marks[0], s.marks[1], s.marks[2]);
printf("Average: %.2f\n", s.average);
printf("Grade: %c\n", s.grade);
}
int main() {
struct Student students[10];
int count = 0, choice, i, searchId;
do {
printf("\n=== Student Management System ===\n");
printf("1. Add Student\n");
printf("2. Display All Students\n");
printf("3. Search Student\n");
printf("4. Exit\n");
printf("Enter choice: ");
scanf("%d", &choice);
switch(choice) {
case 1:
if(count < 10) {
printf("Enter student ID: ");
scanf("%d", &students[count].id);
printf("Enter student name: ");
scanf("%s", students[count].name);
printf("Enter marks for 3 subjects: ");
for(i = 0; i < 3; i++) {
scanf("%f", &students[count].marks[i]);
}
calculateGrade(&students[count]);
count++;
printf("Student added successfully!\n");
} else {
printf("Maximum students reached!\n");
}
break;
case 2:
if(count == 0) {
printf("No students found!\n");
} else {
for(i = 0; i < count; i++) {
displayStudent(students[i]);
}
}
break;
case 3:
printf("Enter student ID to search: ");
scanf("%d", &searchId);
for(i = 0; i < count; i++) {
if(students[i].id == searchId) {
displayStudent(students[i]);
break;
}
}
if(i == count) {
printf("Student not found!\n");
}
break;
}
} while(choice != 4);
return 0;
}
Sample Output:
=== Student Management System === 1. Add Student 2. Display All Students 3. Search Student 4. Exit Enter choice: 1 Enter student ID: 101 Enter student name: John Enter marks for 3 subjects: 85 92 78 Student added successfully!
🔹 Project 2: Tic-Tac-Toe Game
Building a Tic-Tac-Toe game develops game logic, state management, and user interface design for interactive C applications. Create a 3x3 board representation, implement player moves, detect winning conditions or draws, and handle game flow. Implement artificial intelligence for single-player mode or create two-player functionality. Develop clear board display formatting and robust input validation. This project combines conditional logic, loops, and strategic algorithm design. Tic-Tac-Toe is excellent for learning game development fundamentals and AI basics.
#include <stdio.h>
char board[3][3];
char currentPlayer = 'X';
void initializeBoard() {
int i, j;
for(i = 0; i < 3; i++) {
for(j = 0; j < 3; j++) {
board[i][j] = ' ';
}
}
}
void displayBoard() {
printf("\n | | \n");
printf(" %c | %c | %c \n", board[0][0], board[0][1], board[0][2]);
printf("___|___|___\n");
printf(" | | \n");
printf(" %c | %c | %c \n", board[1][0], board[1][1], board[1][2]);
printf("___|___|___\n");
printf(" | | \n");
printf(" %c | %c | %c \n", board[2][0], board[2][1], board[2][2]);
printf(" | | \n\n");
}
int checkWin() {
int i;
// Check rows and columns
for(i = 0; i < 3; i++) {
if((board[i][0] == board[i][1] && board[i][1] == board[i][2] && board[i][0] != ' ') ||
(board[0][i] == board[1][i] && board[1][i] == board[2][i] && board[0][i] != ' ')) {
return 1;
}
}
// Check diagonals
if((board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[0][0] != ' ') ||
(board[0][2] == board[1][1] && board[1][1] == board[2][0] && board[0][2] != ' ')) {
return 1;
}
return 0;
}
int isBoardFull() {
int i, j;
for(i = 0; i < 3; i++) {
for(j = 0; j < 3; j++) {
if(board[i][j] == ' ') {
return 0;
}
}
}
return 1;
}
int main() {
int row, col, gameOver = 0;
initializeBoard();
printf("Welcome to Tic-Tac-Toe!\n");
printf("Players: X and O\n");
printf("Enter row and column (1-3): \n");
while(!gameOver) {
displayBoard();
printf("Player %c's turn: ", currentPlayer);
scanf("%d %d", &row, &col);
row--; col--; // Convert to 0-based indexing
if(row >= 0 && row < 3 && col >= 0 && col < 3 && board[row][col] == ' ') {
board[row][col] = currentPlayer;
if(checkWin()) {
displayBoard();
printf("Player %c wins!\n", currentPlayer);
gameOver = 1;
} else if(isBoardFull()) {
displayBoard();
printf("It's a draw!\n");
gameOver = 1;
} else {
currentPlayer = (currentPlayer == 'X') ? 'O' : 'X';
}
} else {
printf("Invalid move! Try again.\n");
}
}
return 0;
}
Sample Output:
Welcome to Tic-Tac-Toe! Players: X and O Enter row and column (1-3): | | | | ___|___|___ | | | | ___|___|___ | | | | | | Player X's turn: 2 2
🔹 Project 3: Binary Search Algorithm
Implementing binary search with sorting teaches fundamental algorithms and efficient searching techniques critical for optimizing performance in large datasets. First implement a sorting algorithm like quicksort or mergesort to organize data. Then implement binary search that repeatedly divides the search space by half. Compare performance against linear search implementations. This project demonstrates how algorithm choice dramatically impacts performance. Understanding binary search and sorting establishes foundation knowledge for advanced computer science concepts.
#include <stdio.h>
void bubbleSort(int arr[], int n) {
int i, j, temp;
for(i = 0; i < n-1; i++) {
for(j = 0; j < n-i-1; j++) {
if(arr[j] > arr[j+1]) {
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
int binarySearch(int arr[], int n, int target) {
int left = 0, right = n - 1, mid;
while(left <= right) {
mid = left + (right - left) / 2;
if(arr[mid] == target) {
return mid;
}
if(arr[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return -1; // Element not found
}
void displayArray(int arr[], int n) {
int i;
printf("Array: ");
for(i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
}
int main() {
int arr[100], n, i, target, result;
printf("Enter number of elements: ");
scanf("%d", &n);
printf("Enter %d elements: ", n);
for(i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
printf("\nOriginal ");
displayArray(arr, n);
// Sort the array for binary search
bubbleSort(arr, n);
printf("Sorted ");
displayArray(arr, n);
printf("\nEnter element to search: ");
scanf("%d", ⌖);
result = binarySearch(arr, n, target);
if(result != -1) {
printf("Element %d found at position %d (0-based indexing)\n", target, result);
printf("Element %d found at position %d (1-based indexing)\n", target, result + 1);
} else {
printf("Element %d not found in the array\n", target);
}
return 0;
}
Sample Output:
Enter number of elements: 6 Enter 6 elements: 64 34 25 12 22 11 Original Array: 64 34 25 12 22 11 Sorted Array: 11 12 22 25 34 64 Enter element to search: 25 Element 25 found at position 3 (0-based indexing) Element 25 found at position 4 (1-based indexing)
🔹 Project 4: Simple File Manager
Creating a file manager develops file I/O operations, string handling, and directory navigation for building practical file system utilities. Implement functions to create, read, write, and delete text files through a command-line interface. Add directory listing capabilities, file search functionality, and content display options. Develop robust error handling for file operations and edge cases. This project demonstrates practical file system programming. It reinforces file I/O concepts while creating a useful command-line tool.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void createFile() {
char filename[100], content[1000];
FILE *file;
printf("Enter filename: ");
scanf("%s", filename);
file = fopen(filename, "w");
if(file == NULL) {
printf("Error creating file!\n");
return;
}
printf("Enter content (type 'END' on new line to finish):\n");
getchar(); // Clear buffer
while(1) {
fgets(content, sizeof(content), stdin);
if(strcmp(content, "END\n") == 0) {
break;
}
fputs(content, file);
}
fclose(file);
printf("File created successfully!\n");
}
void readFile() {
char filename[100], line[1000];
FILE *file;
printf("Enter filename to read: ");
scanf("%s", filename);
file = fopen(filename, "r");
if(file == NULL) {
printf("Error: File not found!\n");
return;
}
printf("\n--- File Content ---\n");
while(fgets(line, sizeof(line), file) != NULL) {
printf("%s", line);
}
printf("\n--- End of File ---\n");
fclose(file);
}
void appendToFile() {
char filename[100], content[1000];
FILE *file;
printf("Enter filename to append: ");
scanf("%s", filename);
file = fopen(filename, "a");
if(file == NULL) {
printf("Error: File not found!\n");
return;
}
printf("Enter content to append: ");
getchar(); // Clear buffer
fgets(content, sizeof(content), stdin);
fputs(content, file);
fclose(file);
printf("Content appended successfully!\n");
}
void fileInfo() {
char filename[100], ch;
FILE *file;
int characters = 0, words = 0, lines = 0;
int inWord = 0;
printf("Enter filename: ");
scanf("%s", filename);
file = fopen(filename, "r");
if(file == NULL) {
printf("Error: File not found!\n");
return;
}
while((ch = fgetc(file)) != EOF) {
characters++;
if(ch == '\n') {
lines++;
}
if(ch == ' ' || ch == '\t' || ch == '\n') {
if(inWord) {
words++;
inWord = 0;
}
} else {
inWord = 1;
}
}
if(inWord) {
words++;
}
fclose(file);
printf("\n--- File Statistics ---\n");
printf("Filename: %s\n", filename);
printf("Characters: %d\n", characters);
printf("Words: %d\n", words);
printf("Lines: %d\n", lines);
}
int main() {
int choice;
do {
printf("\n=== Simple File Manager ===\n");
printf("1. Create File\n");
printf("2. Read File\n");
printf("3. Append to File\n");
printf("4. File Information\n");
printf("5. Exit\n");
printf("Enter choice: ");
scanf("%d", &choice);
switch(choice) {
case 1:
createFile();
break;
case 2:
readFile();
break;
case 3:
appendToFile();
break;
case 4:
fileInfo();
break;
case 5:
printf("Goodbye!\n");
break;
default:
printf("Invalid choice!\n");
}
} while(choice != 5);
return 0;
}
Sample Output:
=== Simple File Manager === 1. Create File 2. Read File 3. Append to File 4. File Information 5. Exit Enter choice: 1 Enter filename: test.txt Enter content (type 'END' on new line to finish): Hello World! This is a test file. END File created successfully!