0
0
Cprogramming~30 mins

Nested structures - Mini Project: Build & Apply

Choose your learning style9 modes available
Working with Nested Structures in C
📖 Scenario: You are creating a simple program to store information about books in a library. Each book has a title, an author, and a publication year. The author itself has a first name and a last name.
🎯 Goal: Build a program that uses nested structures to store and display information about a book and its author.
📋 What You'll Learn
Define a structure called Author with firstName and lastName as character arrays.
Define a structure called Book that contains a title character array, an Author structure, and an year integer.
Create a variable of type Book and assign exact values to all fields.
Print the book's title, author's full name, and publication year.
💡 Why This Matters
🌍 Real World
Nested structures are used to model complex data like books with authors, addresses with cities, or employees with departments.
💼 Career
Understanding nested structures is important for jobs involving C programming, embedded systems, and software that manages structured data.
Progress0 / 4 steps
1
Define the nested structures
Define a structure called Author with firstName and lastName as character arrays of size 50 each. Then define a structure called Book that contains a title character array of size 100, an Author structure called author, and an integer year.
C
Need a hint?

Use struct keyword to define both Author and Book structures. Remember to include the nested Author inside Book.

2
Create a book variable and assign values
Create a variable called myBook of type struct Book. Assign the title as "The C Programming Language", the author's first name as "Brian", last name as "Kernighan", and the year as 1978. Use strcpy to copy strings.
C
Need a hint?

Remember to include string.h for strcpy. Use dot notation to access nested fields.

3
Write code to print book details
Inside the main function, after assigning values, write printf statements to print the book's title, author's full name (first and last name separated by a space), and publication year on separate lines.
C
Need a hint?

Use printf with format specifiers %s for strings and %d for integers. Access nested fields with dot notation.

4
Run the program and display output
Run the program and print the output exactly as shown:
Title: The C Programming Language
Author: Brian Kernighan
Year: 1978
C
Need a hint?

Make sure your printf statements match the expected output exactly, including spaces and new lines.