⚡0 XP🔥0

Project: Student Record System

Lesson 13 of 13 ⏱ 4 min read ✎ 2 exercises ❓ 3-question quiz ▶ Runs C

Build a menu-driven student record manager in C using structures, arrays, functions, pointers and string handling - the classic first-year project.

Time to combine everything: structures, arrays, functions, pointers, strings and a menu loop. You will build a small Student Record System - the kind of project asked in first-year practicals and viva exams.

What the program does#

  1. Add a student (roll number, name, marks)
  2. Display all students in a table
  3. Search a student by roll number
  4. Show the topper and the class average
  5. Exit

Step 1: the data model#

#define MAX 100

typedef struct {
    int roll;
    char name[30];
    int marks;
} Student;

All records live in Student list[MAX], and int count says how many are filled.

Step 2: one function per menu option#

  • void addStudent(Student list[], int *count) - reads one record and increments *count (pointer, because it must change count in main).
  • void display(const Student list[], int count) - prints a table.
  • int findByRoll(const Student list[], int count, int roll) - returns the index or -1.
  • void report(const Student list[], int count) - topper and average.
हिंदी में समझें

बड़े program को छोटे-छोटे functions में बाँटिए - हर menu option के लिए एक function। count बदलना है तो उसका address (&count) भेजिए। जो function data सिर्फ़ पढ़ते हैं, उनमें const लिखिए ताकि गलती से data न बदले।

Step 3: the complete program#

The input box below simulates a user typing menu choices: add three students, display, search roll 102, report, exit. Change the input to try other choices.

▶ Try it YourselfC
Ctrl + Enter to run
Output
Added Aarav
Added Diya
Added Kabir
Roll   Name       Marks
101    Aarav         72
102    Diya          88
103    Kabir         65
Found: Diya, marks 88
Topper: Diya (88)
Class average: 75.00
Goodbye!

How it works#

  • The do-while loop keeps showing the menu until choice 5.
  • Student *s = &list[*count]; gives a pointer to the next free slot, so s->roll writes straight into the array.
  • const Student list[] documents that display and report never modify the data.
  • findByRoll returns -1 for "not found" - a common C convention.

Ideas to extend it#

  1. Save and load the records to a file with fprintf/fscanf so data survives restarts.
  2. Delete a student (shift the later records one place left).
  3. Grades - add a char grade member computed from marks.
  4. Dynamic size - replace the fixed array with malloc/realloc.
  5. Sort the list by marks or name (see the exercises).
Tip

In a viva, be ready to explain: why count is passed as a pointer, the difference between . and ->, why strcmp is needed for names, and what happens if more than MAX students are added.

Summary#

You used typedef struct, arrays of structures, functions with pointer parameters, const, string input and a menu loop with switch - the core of C programming. Next, try the C++ course to see how classes make this kind of program even cleaner.

Practice Exercises

Write your code, then press Check. Your program is tested automatically.

1

Count passed students

Add a function int countPassed(Student s[], int n) that returns how many students have marks >= 40. With the data in main, print Passed: 3 of 4.

Expected output:
Passed: 3 of 4
2

Sort by marks (descending)

Sort the array of students by marks, highest first (swap whole structs), and print the rank list:

1. Kabir 91
2. Aarav 72
3. Meera 55
4. Diya 38
Expected output:
1. Kabir 91
2. Aarav 72
3. Meera 55
4. Diya 38

Quick Quiz

Q1.

Why does addStudent take int *count instead of int count?

Q2.

Which function compares two names correctly?

Q3.

What keeps the menu running until the user chooses Exit?