0
0
Cprogramming~30 mins

Array of structures - Mini Project: Build & Apply

Choose your learning style9 modes available
Array of structures
📖 Scenario: You are managing a small library system. You want to store information about books including their title and number of pages.
🎯 Goal: Create an array of structures to hold book information, then print the details of each book.
📋 What You'll Learn
Define a structure named Book with two members: title (string) and pages (integer).
Create an array named library of 3 Book structures with exact titles and page counts.
Use a loop to print each book's title and page count.
💡 Why This Matters
🌍 Real World
Storing and managing collections of related data like books, students, or products is common in software applications.
💼 Career
Understanding arrays of structures is essential for working with complex data in C programming jobs, especially in systems programming and embedded development.
Progress0 / 4 steps
1
Define the Book structure and create the library array
Define a structure called Book with a char array title[50] and an int pages. Then create an array called library of 3 Book elements with these exact entries: {"C Programming", 250}, {"Data Structures", 300}, {"Algorithms", 400}.
C
Need a hint?

Use struct keyword to define the structure. Use curly braces to initialize the array with exact titles and pages.

2
Create a variable to hold the number of books
Create an int variable called num_books and set it to 3 to represent the number of books in the library array.
C
Need a hint?

Just create a simple integer variable and assign the value 3.

3
Use a for loop to print each book's details
Write a for loop using int i from 0 to less than num_books. Inside the loop, print the book's title and pages using library[i].title and library[i].pages.
C
Need a hint?

Use a for loop with i from 0 to num_books - 1. Use printf to show the title and pages.

4
Print the final output
Run the program to print the details of all books in the library array.
C
Need a hint?

Make sure your program prints each book's title and pages on a new line exactly as shown.