Computer Programming C Laboratory: Structures C Programs

C Program to store 3 records in one structure

Using Structure - C Programming

C Program to store 3 records in one structure.

/* C Program to store 3 records in one structure */

#include<stdio.h>

#include <conio.h>

struct book /* book is a structure with elements */.

{

char name[10];

int price;

int pages;

};

struct book b[3];

void main()

{

int i; /*Local definitions */

/* Statements */

clrscr();

for(i=1;i<=3;i++)

{

printf("Enter book name, price and pages: \n");

scanf("%s %d %d", &b[i].name, &b[i].price, &b[i].pages);

} /* for */

for(i=1;i<=3;i++)

printf("\n%s\t %d\t%d", b[i].name, b[i].price, b[i].pages);

getch();

} /* main */

OUTPUT:

Enter book name, price and pages:

English 165  200

Enter book name, price and pages:

Maths 300 450

Enter book name, price and pages:

Physics 250 370

English 165 200

Maths 300 450

Physics 250 370

EXPLANATION: Here struct book b[3] creates space in memory to store 3 structure variables. In an array of structures all elements of the array are stored in adjacent memory locations. Since each element of this array is a structure. We can very well visualize the arrangements of array of structures in memory. In our example b[0]'s name, price and pages in memory would be immediately followed by b[1]'s name, price and pages, and so on.

 

Computer Programming C Laboratory: Structures C Programs : Tag: C Programming : - C Program to store 3 records in one structure


Computer Programming C Laboratory: Structures C Programs



Under Subject


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation



Related Subjects


English Essentials I

EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


தமிழர் மரபு - Heritage of Tamils

UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Calculus

MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I

PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Chemistry I

CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Makerspace

ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming Python

CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Fundamentals of Electrical and Electronics Engineering

EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Mechanical Engineering

ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Civil Engineering

CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing

CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I Laboratory

PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Applied Chemistry I Laboratory

CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming Python Laboratory

CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Engineering Drawing

ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electronics and Electrical Engineering

EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing - Laboratory

CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation