In: Computer Science
Create a nested structure in C (one structure that contains another) and print out all the fields in both structures. The main structure should have fields for: movie name and the year it was released. The extended structure should include the original structure as well as fields for: Lead actor, genre and runtime.
Programming Language C program which has a nested structure and displays all the field of both the structure.
#include <stdio.h>
#include <string.h>
//structure Movie
struct Movie
{
//variable declaration
char movieName[50];
int movieYear;
};
//structure MovieExt
struct MovieExt
{
//variable declaration
char leadActor[50];
char genre[50];
int runtime;
//struct Movie variable declaration
struct Movie m;
};
int main()
{
struct MovieExt mov = {"ABC", "DEF", 10, "PQR", 2009};
//display actor, genre, runtime, name, and year
printf("Lead Actor: %s \n", mov.leadActor);
printf("Genre: %s \n", mov.genre);
printf("Runtime: %d \n\n", mov.runtime);
printf("Name: %s \n", mov.m.movieName);
printf("Year: %d \n", mov.m.movieYear);
return 0;
}
OUTPUT:
Lead Actor: ABC
Genre: DEF
Runtime: 10
Name: PQR
Year: 2009