×

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

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.

Find Union and Intersection of Two Arrays in C

Union You can find the union of the two sorted arrays using the join merge method on arr1[] and arr2[]. Use two index variables i and j with initial values i =...

4 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.

Classification of Programming language

 Classification of Programming language  The programming language represents a set of instructions compiled along with each other to perform a specific task provided by the CPU (Central Processing Unit). A programming...

3 minutes read.

Comments in C

Comments are used to comment on the line of code in the program. Comments are a way of inserting remarks and reminders into code without affecting its behavior. The compiler...

1 minute read.

Error handling in C

Error handling in C: The C programming standard does not provide direct convenience for handling the errors. However, being a system programming language, it definitely will give access to handling...

4 minutes read.

Length of an Array Function in C

In C, there is no built-in function to get the length of an array. However, there are a few ways you can determine the length of an array. It is necessary...

15 minutes read.

Return array from function in C

Return array from function in C C programming does not require the return to a function of a whole array as an argument. However, you can return a pointer to an array without...

2 minutes read.

Sum of digits in C++

Sum of digits in C++ There are various ways to find the sum of the digits of a number in C++. We can use containers like arrays or other simple cases...

4 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.

Selection sort in C

In the C standard, the selection sorting technique exists where the smallest among the unsorted elements of the array is selected at each time and is then inserted into its...

3 minutes read.

How to create a node in C?

A node is a small concept taken from the graph theory, or a node is a fundamental unit of a data structure, like a tree data structure. Every graph contains...

3 minutes read.

Unformatted input() and output() function in C

Unformatted Input and Output functions take the character, character array, and strings as input. We can read-only character data types with these functions. These functions are already defined in the...

5 minutes read.

Armstrong program in C using function

In this article we will learn how to find Armstrong of a number using function in C. An Armstrong number is a three-digit number that is the sum of its separate...

1 minute read.

Pure Virtual Function in C

Before knowing about the pure virtual function some of the important points about the virtual function in C++ are given below. In c++ the member function that is defined in the...

4 minutes read.

Decimal to Binary in C

What is a decimal number? A decimal number is a number represented in the decimal number system. This system of binary conversion uses base 10 to represent numbers, i.e. the digits...

3 minutes read.

Typecast vs. typedef in C

Typecast vs. typedef in C Typecast In the C programming language, converting the data type from one form to another is known as type casting or the type conversion. It is a...

5 minutes read.

Continue in C

C language: C language is a procedure oriented programming language. We can say that it is a platform dependent language. C language is introduced by Dennis Ritchie in the year 1970. We...

2 minutes read.

Do WHILE LOOP in C Programming Examples

Before understanding the programming examples of the Do-While loop, we have to know what is Do-While loop in C. So, let's start with the definition of the Do-While loop. What is...

5 minutes read.

Why does sizeof(x++) not Increment x in C

Sizeof() is a much-involved operator in C or C++. It is an incorporated time unary administrator which can be utilized to figure the size of its operand. The consequence of...

5 minutes read.