English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

C program stores student information in the structure

Comprehensive Collection of C Programming Examples

In this example, you will learn to store5name students' information.

To understand this example, you should know the followingC programming languageTopic:

Store information in the structure and display

#include <stdio.h>
struct student {
    char firstName[50];
    int roll;
    float marks;
}10];
int main() {
    int i;
    printf("Input student information:\n");
    //stored information
    for (i = 0; i < 5; ++i) {
        s[i].roll = i + 1;
        printf("\nFor roll number%d,\n", s[i].roll);
        printf("Enter first name:  ");
        scanf("%s", s[i].firstName);
        printf("Enter marks:  ");
        scanf("%f", &s[i].marks);
    }
    printf("Display information:\n\n");
    //Display information
    for (i = 0; i < 5; ++i) {
        printf("\nRoll number:  %d\n", i + 1);
        printf("First name:  ");
        puts(s[i].firstName);
        printf("Marks:  %.1f", s[i].marks);
        printf("\n");
    }
    return 0;
}

Output result

Input student information: 
For roll number1,
Enter name:  Tom
Enter marks: 98
For roll number2,
Enter name:  Jerry
Enter marks: 89
.
.
.
Display information:
Roll number: 1
Name:  Tom
Marks: 98
.
.
.

In this program, a structure named student will be created. The structure has three members: name (string), roll (integer), and   marks (floating-point numbers).

Then, we created a structure array s with elements5, to store5student's information.

This program Use a for loop to get5Enter the information of a student and store it in a structure array. Then, use another for loop to display the user input information on the screen.

Comprehensive Collection of C Programming Examples