Student Management System in C

Last Updated : 2 Aug, 2025

Making projects is one of the most interesting and fun ways to learn a programming language such as C. In this article, we will learn how to write code for the Student Management System in C.

Student Management System

This project is a simple console-based Student Management System built using the C programming language. It allows for basic operations such as:

  • Adding student records
  • Deleting students by ID
  • Searching for a student by ID
  • Displaying all students belonging to a specific class

The system uses a singly linked list to dynamically manage student records in memory. Each student is represented by a struct that stores details such as their ID, name, age, gender, and class number.

Components of the Project

The whole project contains features as follows:

  1. Add Student: Adds a new student to the beginning of the list with provided details.
  2. Delete Student: Deletes a student based on their ID. If the ID doesn't exist, it notifies the user.
  3. Search Student: Finds and displays a student record by ID if it exists.
  4. Display by Class: Lists all students who belong to a given class, showing their ID, name, age, and gender.

Expected Output Behaviour:

1. Add Student

The addStudent function takes arguments such as id, name, age, gender, and classNumber. It dynamically allocates memory for a new student using malloc, assigns these values to the respective fields of the student structure, and then inserts the student at the beginning of the linked list.

C
// Function to add a student
void addStudent(int id, const char *name, int age, const char *gender, int classNumber) {
    Student *s = malloc(sizeof(Student));
    s->id = id;
    strcpy(s->name, name);
    s->age = age;
    strcpy(s->gender, gender);
    s->classNumber = classNumber;
    s->next = head;
    head = s;
    printf("Student %s added successfully.\n", name);
}

2. Delete Student

C
// Function to delete a student by ID
void deleteStudent(int id) {
    Student *prev = NULL, *cur = head;
    while (cur && cur->id != id) {
        prev = cur;
        cur = cur->next;
    }
    if (!cur) {
        printf("Student with ID %d not found.\n", id);
        return;
    }

    if (prev) prev->next = cur->next;
    else head = cur->next;

    free(cur);
    printf("Student with ID %d deleted.\n", id);
}

The deleteStudent function takes a student ID as input and searches through the linked list to find a matching student. If found, it removes that student from the list by updating the pointers, frees the allocated memory for that student using free(), and prints a confirmation message. If the student is not found, it displays an appropriate message.

3. Search Student

C
// Function to search a student by ID
void searchStudent(int id) {
    Student *cur = head;
    while (cur) {
        if (cur->id == id) {
            printf("Student Found:\n");
            printf("ID: %d\nName: %s\nAge: %d\nGender: %s\nClass: %d\n",
                   cur->id, cur->name, cur->age, cur->gender, cur->classNumber);
            return;
        }
        cur = cur->next;
    }
    printf("Student with ID %d not found.\n", id);
}

The searchStudent function takes a student ID as input and traverses the linked list to find a student with the matching ID. If found, it prints the student's details such as ID, name, age, gender, and class number. If no student with the given ID is found, it displays a message indicating that the student does not exist.

4. Display by Class

C
// Function to display students by class
void displayByClass(int classNum) {
    Student *cur = head;
    int count = 0;
    printf("Students in Class %d:\n", classNum);
    while (cur) {
        if (cur->classNumber == classNum) {
            printf("ID: %d | Name: %s | Age: %d | Gender: %s\n",
                   cur->id, cur->name, cur->age, cur->gender);
            count++;
        }
        cur = cur->next;
    }
    if (count == 0) printf("No students found in Class %d.\n", classNum);
}

The displayByClass function takes a class number as input and traverses the entire linked list of students. It prints the details (ID, name, age, gender, and class number) of all students who belong to the given class. If no students are found in that class, it displays an appropriate message.

C Program for Student Management System

Below is the full program for the Student Management System in C language:

C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct Student {
    int id;
    char name[50];
    int age;
    char gender[10];
    int classNumber;
    struct Student *next;
} Student;

Student *head = NULL;

// Function to add a student
void addStudent(int id, const char *name, int age, const char *gender, int classNumber) {
    Student *s = malloc(sizeof(Student));
    s->id = id;
    strcpy(s->name, name);
    s->age = age;
    strcpy(s->gender, gender);
    s->classNumber = classNumber;
    s->next = head;
    head = s;
    printf("Student %s added successfully.\n", name);
}

// Function to delete a student by ID
void deleteStudent(int id) {
    Student *prev = NULL, *cur = head;
    while (cur && cur->id != id) {
        prev = cur;
        cur = cur->next;
    }
    if (!cur) {
        printf("Student with ID %d not found.\n", id);
        return;
    }

    if (prev) prev->next = cur->next;
    else head = cur->next;

    free(cur);
    printf("Student with ID %d deleted.\n", id);
}

// Function to search a student by ID
void searchStudent(int id) {
    Student *cur = head;
    while (cur) {
        if (cur->id == id) {
            printf("Student Found:\n");
            printf("ID: %d\nName: %s\nAge: %d\nGender: %s\nClass: %d\n",
                   cur->id, cur->name, cur->age, cur->gender, cur->classNumber);
            return;
        }
        cur = cur->next;
    }
    printf("Student with ID %d not found.\n", id);
}

// Function to display students by class
void displayByClass(int classNum) {
    Student *cur = head;
    int count = 0;
    printf("Students in Class %d:\n", classNum);
    while (cur) {
        if (cur->classNumber == classNum) {
            printf("ID: %d | Name: %s | Age: %d | Gender: %s\n",
                   cur->id, cur->name, cur->age, cur->gender);
            count++;
        }
        cur = cur->next;
    }
    if (count == 0) printf("No students found in Class %d.\n", classNum);
}

int main() {

    addStudent(101, "Alice", 14, "Female", 10);
    addStudent(102, "Bob", 15, "Male", 10);
    addStudent(103, "Charlie", 13, "Male", 9);
    addStudent(104, "Daisy", 14, "Female", 10);

    printf("\n Searching for ID 102 \n");
    searchStudent(102);

    printf("\n Deleting ID 103 \n");
    deleteStudent(103);

    printf("\n Display Class 10 \n");
    displayByClass(10);

    printf("\n Display Class 9 \n");
    displayByClass(9);

    return 0;
}

Comment