C Program: Simple Student Record System Download Source Code

0
292

Student record system is a technique by which we maintain the record of different students. In c language we use a structure pointer of file type to declare a file.

We begin the code with including the header files “stdio.h” “conio.h” “stdlib.h”  “string.h”

We take count as a global variable because it is used in different segments of the program and we want it to retain its value.

A structure ‘student’ for the student’s record is declared containing name age and roll no inside it.

Now we run the switch-case statement as we have to perform different operations relating to students records like:-

  1. Create record
  2. List record
  3. Add another record
  4. Exit

We write the switch-case statements inside a do-while loop because we want to run it again in case we want to list or see the record stored or add another entry in the record till the user want to exit and thus will choose 4.

In case 1:

User creates a new file and opens it using the code

There are different types of ways to open a file namely

“a”=adding new contents at the end of file

“r+”=reading existing contents and writing new contents to a file

“w”=writing new contents in a file and reading them back

Here if the file is not created due to reason like lack of memory then the pointer “fp” will return “NULL” and in such case the program won’t execute and just exit, Else the file will be created and you can enter the name, age and roll number or the student and it will be saved in the file by “fprintf” statement.

When you are done entering the records you can press 0 and the case would execute the break statement and you would again be asked to choose from the 4 choices again

In case 2

if after creating the record the user wants to review it ,it can easily be done by going to the second case which first reads the file

In case 3

In this case , you can add another entry in the file in case you forgot it in the beginning and hence it uses ‘a’ to read the file as contents or entries have to be added at the end on the file

And after this statement “fp”  points to the end of the file and hence more entries can be added.

In case 4

This case is basically to exit the program.

I have used count to print all the entries I am entering but you can choose the amount of entries you want to see. Most easy way to understand this program is by understanding the logic of the program

Download C Program: Simple Student Record System

LEAVE A REPLY

Please enter your comment!
Please enter your name here