Create Student Record System in C Programming

Faraz

By Faraz -

Learn how to create a student record system in C programming with simple steps. Follow our guide to build, compile, and run your C program easily.


create-student-record-system-in-c-programming.webp

Introduction

Creating a student record system in C programming is a great project to practice your coding skills. This system allows you to store, update, delete, and display student records efficiently. In this blog, we will guide you through the steps to build, compile, and run your own student record system in C.

Step-by-Step Instructions

1. Set Up Your Development Environment

Before starting, ensure you have a C compiler installed. You can use GCC, which is available on most platforms.

2. Create the Program Structure

First, open your code editor and create a new C file. Let's start by defining the structure for student records.

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

#define MAX 50

struct Student {
    int id;
    char name[100];
    float marks;
};

struct Student students[MAX];
int count = 0;

3. Add Functions for CRUD Operations

We need functions to create, read, update, and delete student records. Let's add these functions one by one.

Add Student Function

void addStudent() {
    if (count < MAX) {
        struct Student s;
        printf("Enter Student ID: ");
        scanf("%d", &s.id);
        printf("Enter Student Name: ");
        scanf("%s", s.name);
        printf("Enter Student Marks: ");
        scanf("%f", &s.marks);
        
        students[count] = s;
        count++;
        printf("Student added successfully!\n");
    } else {
        printf("Student list is full!\n");
    }
}

Display Students Function

void displayStudents() {
    if (count == 0) {
        printf("No students to display.\n");
    } else {
        for (int i = 0; i < count; i++) {
            printf("ID: %d, Name: %s, Marks: %.2f\n", students[i].id, students[i].name, students[i].marks);
        }
    }
}

Update Student Function

void updateStudent() {
    int id;
    printf("Enter Student ID to update: ");
    scanf("%d", &id);
    for (int i = 0; i < count; i++) {
        if (students[i].id == id) {
            printf("Enter new Name: ");
            scanf("%s", students[i].name);
            printf("Enter new Marks: ");
            scanf("%f", &students[i].marks);
            printf("Student record updated successfully!\n");
            return;
        }
    }
    printf("Student not found!\n");
}

Delete Student Function

void deleteStudent() {
    int id;
    printf("Enter Student ID to delete: ");
    scanf("%d", &id);
    for (int i = 0; i < count; i++) {
        if (students[i].id == id) {
            for (int j = i; j < count - 1; j++) {
                students[j] = students[j + 1];
            }
            count--;
            printf("Student record deleted successfully!\n");
            return;
        }
    }
    printf("Student not found!\n");
}

4. Create a Menu for User Interaction

Now, let's create a menu to interact with the user.

void menu() {
    int choice;
    do {
        printf("\nStudent Record System\n");
        printf("1. Add Student\n");
        printf("2. Display Students\n");
        printf("3. Update Student\n");
        printf("4. Delete Student\n");
        printf("5. Exit\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch(choice) {
            case 1:
                addStudent();
                break;
            case 2:
                displayStudents();
                break;
            case 3:
                updateStudent();
                break;
            case 4:
                deleteStudent();
                break;
            case 5:
                printf("Exiting...\n");
                break;
            default:
                printf("Invalid choice! Please try again.\n");
        }
    } while(choice != 5);
}

5. Main Function

Finally, let's add the main function to run our program.

int main() {
    menu();
    return 0;
}

Compiling and Running the Program

Compiling the Program

To compile your program, open the terminal and navigate to the directory where your C file is saved. Run the following command:

gcc -o student_record_system student_record_system.c

This command will compile your C program and create an executable file named student_record_system.

Running the Program

To run the program, enter the following command in the terminal:

student_record_system

You will see the menu displayed, and you can start adding, displaying, updating, and deleting student records.

Conclusion

Creating a student record system in C programming is a useful project to enhance your coding skills. By following the steps outlined in this guide, you can build a functional system that allows you to manage student records efficiently. Practice these steps, and soon you'll be comfortable with C programming and managing data structures.

This project not only helps you learn the basics of C but also gives you an understanding of how to handle data and perform CRUD operations. Keep experimenting with different features and functions to make your program even more robust.

That’s a wrap!

I hope you enjoyed this article

Did you like it? Let me know in the comments below 🔥 and you can support me by buying me a coffee.

And don’t forget to sign up to our email newsletter so you can get useful content like this sent right to your inbox!

Thanks!
Faraz 😊

End of the article

Subscribe to my Newsletter

Get the latest posts delivered right to your inbox


Latest Post

Please allow ads on our site🥺