×

C program to Store Information of Students Using Structure

What is the Structure in C?

User-defined data types include structures. Structures aid your ability to combine things of various categories into a single group. Like arrays, it operates similarly. A variety of various data types are stored there.

A structure is a made-up building or a particular grouping of objects or people, especially with several elements.

C programming structures are given below:

Link, Definition, Documentation, Global Declaration Subprogrammes and the Main() function. The main() function must be present in every C programme; the other functions are optional.

Benefits of Structure

Since we can use a single name to describe the entire record, maintaining it is quite simple. We can use a single argument in Structure to pass an entire set of records to any function. To store more records with related types, use an array of Structures.

The program produces a structured student. Three components make up the Structure: names (string), rolls (integer), and marks (float).

In C, a user-defined data type is called a structure. An item with potentially many types can be combined into a single type using the data type that a structure offers.

The student structure is built using the 'struct' keyword as follows:

struct Student

{

char* name;

int roll_number;

int age;

double total_marks;

};

Here is a sample program on how to store information about students and display it using Structure,

// Store information of students and display it using Structure
#include<stdio.h>
#include<conio.h>
Struct student{
char name[50];//declaration of file of char type
int roll;
float marks;
}
int main()
{
printf("Enter information:\n");// requests that the user enter information
printf("Enter name: ");// seeks the user to enter the name
fgets(s,.name,size of(s.name),stdin);// File input


printf("Enter roll number:");// seeks the user to enter the roll number
scanf("%d,&s.roll");// to make loop ends
printf("%f",&s.marks);
printf("Display Information:\n");// Displays the information 
printf("Name: ");// prints the information required
printf("%s",s.name);
printf("Roll number: %d\n",s.roll);// prints the information required
printf("Marks:%1f\n",s.marks);
return 0;
}

Output

Enter information:
Enter name: Bittu
Enter roll number: 025
Enter marks: 86.5
Display Information:
Name: Bittu
Roll number: 25
Marks: 86.500000

The above program is based on only particular student information students using Structure.

Find out how many students' information will be kept on file. We are only taking 5 students in this instance to keep things simple. To access the data, create a Student structure variable. Here, it is assumed to mean "student."

Retrieve the information for n students using the dot (.) operator, then enter it into the fields for each student.

Syntax:

Student[i].member = value;

Use the dot (.) operator and a loop to print the records of each student after all the data has been recorded.

Syntax:

Student[i].member;

/* This program is based on data from five students who used Structure.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Create the student structure
struct Student {
char* name;
int roll_number;
int age;
double total_marks;
};
// Driver code
int main()
{
int i = 0, n = 5;
// Make a variable for the student's Structure.
// with n records for students
struct Student student[n];
// Obtain student information
student[0].roll_number = 1;
student[0].name = "Bittu";
student[0].age =21;
student[0].total_marks = 80.26;
student[1].roll_number = 4;
student[1].name = "Chintu";
student[1].age = 18;
student[1].total_marks = 90.74;
student[2].roll_number = 2;
student[2].name = "Yash";
student[2].age = 11;
student[2].total_marks = 87.54;
student[3].roll_number = 5;
student[3].name = "Sunny";
student[3].age = 12;
student[3].total_marks = 76.39;
student[4].roll_number = 3;
student[4].name = "Sohail";
student[4].age = 13;
student[4].total_marks = 81.22;
// Print the Students information
printf("Student Records:\n\n");
for (i = 0; i < n; i++) {
printf("\tName = %s\n", student[i].name);
printf("\tRoll Number = %d\n", student[i].roll_number);
printf("\tAge = %d\n", student[i].age);
printf("\tTotal Marks = %0.2f\n\n", student[i].total_marks);
}
return 0;
}

Output

Student Records:


Name = Bittu
Roll Number = 1
Age = 21
Total Marks = 80.26


Name = Chintu
Roll Number = 4
Age = 18
Total Marks = 90.74


Name = Yash
Roll Number = 2
Age = 11
Total Marks = 87.54


Name = Sunny
Roll Number = 5
Age = 12
Total Marks = 76.39


Name= Sohail
Roll Number = 3
Age = 13
Total Marks = 81.22

Explanation

With the help of structures, this software keeps the data (name, roll, and marks) of 5 students.

This program creates a structure for the students.

Name (string), roll (integer), and marks (marks) are the three components that make up this Structure (float).

The application retrieves the data for 5 students from the user and shows it on the screen using a loop.


Related Topics

Calendar application in C

Introduction to the calendar application We all are familiar with the calendar. It plays a crucial role in our daily life. We run toward the calendar whenever we want to know...

6 minutes read.

getc() function in C

Getc is one of the file handling technique in C. The Getc() is a C library function gets the next character or new characters  from the specific stream and supports...

4 minutes read.

Simple Programs in C Language

In this article, we will discuss the basic programs in C language. Addition of two values in C. Swapping two values. Finding the odd or even values. Finding vowels and consonants in C. Finding the...

11 minutes read.

Types Of Structures In C

We can normally store elements of the same datatype with the help of an array in C programming. We can store multiple numbers of elements of a character data type...

3 minutes read.

Fahrenheit to Celsius in C

Before going into conversion, we have to know what Fahrenheit and Celsius mean, these are both units to measure the temperature.In our daily life, we use both Fahrenheit and Celsius,...

1 minute read.

Booleans in C

Introduction to Boolean With all the complexities of programming, it can take time to understand the basics. One concept, in particular, that confuses many beginners is the use of Booleans in...

6 minutes read.

Static in C

Static is a keyword that is used in the C programming language. It can be used both as variables and as functions. In other words, it can be declared both...

3 minutes read.

Pi() Function in C

Pi: Mathematic constants are not defined in the c or c++ programming languages. To use the Mathematical constants firstly, we have to define the _USE_MATH_DEFINES and then declare the cmath and...

3 minutes read.

How to convert a number to words in C

There are many ways available for converting an integer or a number to its word form. For example, consider a number as 12345. This number can be represented in two...

3 minutes read.

Enumeration (Enum) in C

Enumeration (Enum) in C: In the C programming language, the enum is referred to as an enumerated type. Enum is a user defined data type consisting of integer values and...

3 minutes read.

Difference between rand() and srand() function in C

What is the rand()? The rand() means random function. This function is used in C. It generates random numbers in the range of 0 to the RAND_MAX. Suppose we generate a...

3 minutes read.

Entry Control Loop in C

Initially, an entry control loop verifies the termination condition at the entry point. After that, its control passes to the main body of the while or for loop if the...

3 minutes read.

Distance Vector Routing Protocol Program in c

A distance-vector routing protocol is one of the foremost instructions of routing protocols in pc conversation principle for packet-switched networks. The hyperlink-nation protocol is the alternative foremost class.The Bellman-Ford set...

4 minutes read.

Limitations of Inline Function in C

The compiler is unable to conduct inlining in two instances. It just accepts the inline definitions and produces space for the function in the same way it does for a...

3 minutes read.

Keywords in C

A keyword is a word that has a predetermined meaning. The C compiler knows the purposes of the keywords. The objectives of these keywords cannot be modified. Keywords are the...

9 minutes read.

How to use sine() function in C

What is Function? The function is a set of statements. It takes input and performs some computation to produce output. The process is a set of codes only achieved when it is...

3 minutes read.

Control statement in C

What is a control statement? A control statement helps us to control the flow of the program. The control statement helps us to execute the program's instructions in a user-defined order....

8 minutes read.

What is 2s Complement in C?

The complement of 2s in C is generated from the 1s in C. As we know, the 1s complement of a binary number is generated by converting bit 1 to...

4 minutes read.

Macros in C

In the C programming language, the macro is defined as a segment of the code replaced by the macro defined value at the beginning. ‘#define’ is the directive that defines...

3 minutes read.

Library Functions in C

What are library functions? Library functions are the built-in functions (functions provided by the system) which are stored in the library. The library is the common location where these functions are...

3 minutes read.