---
title: "College records with nested date structure"
subject: "Computer Programming"
chapter: 8
key: "semester_1/computer_programming:struct-college-estdate"
source: https://www.bctengineer.com/q/semester_1/computer_programming/struct-college-estdate
site: BCT Engineering
---

# College records with nested date structure

Computer Programming · Chapter 8: Structures

- Asked in: 2072 Chaitra, 8 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/struct-college-estdate
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-8

## Question

Write a program to read structure "college" having name, estDate and location where estDate is another structure having day, month and year as members. Display the records of 10 colleges.

## Short answer

Define a nested structure date inside college. Read 10 sets using scanf with &c[i].estDate.day, &c[i].estDate.month, &c[i].estDate.year. Display in a table with date formatted using %02d/%02d/%-6d.

## Answer

**Design.** The structure `date` (day, month, year) is defined first. The structure `college` contains `name`, `estDate` (a `struct date`, the nested structure) and `location`. An array of 10 colleges is read in a loop; the nested members are reached with two dots, such as `c[i].estDate.year`. The records are then displayed in a table.

```c
#include <stdio.h>
#define N 10

struct date {
    int day, month, year;
};

struct college {
    char name[40];
    struct date estDate;      /* nested structure */
    char location[30];
};

int main(void)
{
    struct college c[N];

    for (int i = 0; i < N; i++) {
        printf("College %d name: ", i + 1);
        scanf("%39s", c[i].name);
        printf("Established date (day month year): ");
        scanf("%d %d %d", &c[i].estDate.day, &c[i].estDate.month, &c[i].estDate.year);
        printf("Location: ");
        scanf("%29s", c[i].location);
    }

    printf("\n%-12s %-12s %s\n", "Name", "Est. date", "Location");
    for (int i = 0; i < N; i++)
        printf("%-12s %02d/%02d/%-6d %s\n", c[i].name, c[i].estDate.day,
               c[i].estDate.month, c[i].estDate.year, c[i].location);
    return 0;
}
```

**Sample run** (10 colleges entered; only the output after the input is shown)

Input (entered one after another): `Pulchowk 5 10 1984 Lalitpur Thapathali 9 2 2011 Kathmandu Purwanchal 25 8 2010 Dharan Paschimanchal 21 7 1993 Pokhara Kathmandu 4 8 1981 Kavre Pokhara 27 7 2007 Pokhara Himalaya 20 1 2008 Lalitpur Janakpur 9 12 1994 Dhanusha Nepal 19 2 2000 Banepa Eastern 1 1 1981 Biratnagar`

```text
Name         Est. date    Location
Pulchowk     05/10/1984   Lalitpur
Thapathali   09/02/2011   Kathmandu
Purwanchal   25/08/2010   Dharan
Paschimanchal 21/07/1993   Pokhara
Kathmandu    04/08/1981   Kavre
Pokhara      27/07/2007   Pokhara
Himalaya     20/01/2008   Lalitpur
Janakpur     09/12/1994   Dhanusha
Nepal        19/02/2000   Banepa
Eastern      01/01/1981   Biratnagar
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. In struct college, what is estDate?
   A. An int
   B. A string
   C. A member of type struct date (nested structure)
   D. A pointer
   Answer: C. estDate holds day, month and year. (Key point: Nested member)

2. Which must be defined first?
   A. struct college
   B. Either, order does not matter
   C. main()
   D. struct date, before struct college
   Answer: D. The inner type must exist first. (Key point: Definition order)

3. How is the year of the i-th college accessed?
   A. c[i].estDate.year
   B. c.estDate[i].year
   C. c[i]->year
   D. estDate.c[i].year
   Answer: A. Index, then two dots. (Key point: Access)

4. How many records are read?
   A. 1
   B. 10, using an array of struct college in a loop
   C. Unlimited without an array
   D. 5
   Answer: B. N is defined as 10. (Key point: Array)

5. How is the day read?
   A. scanf("%d", c[i].estDate.day)
   B. scanf("%s", c[i].day)
   C. scanf("%d", &c[i].estDate.day)
   D. scanf("%d", &c.day)
   Answer: C. The address of the member is needed. (Key point: Scanf nested)

## Related in Computer Programming

- [Display records sorted by name from file](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-sorted-records-by-name) — Computer Programming, chapter 10
- [Read records until end; show nth record](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-worker-nth-record) — Computer Programming, chapter 10, asked 2×
- [Height difference using nested structure](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-height-feet-inches) — Computer Programming, chapter 8
- [Student records with two functions](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-student-read-display-functions) — Computer Programming, chapter 8
- [Sending structure members to a function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astructure-members-to-function) — Computer Programming, chapter 8
- [Insert a string into another string](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Ainsert-string-into-string) — Computer Programming, chapter 7

## Related in other subjects

- [Date of birth validation with exceptions](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Adob-exception-program) — Object Oriented Programming, chapter 10
- [File stream; student binary file program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afile-stream-student-binary) — Object Oriented Programming, chapter 8
- [Student records file with CRN search](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Astudent-crn-file-search) — Object Oriented Programming, chapter 8
- [Write and display 10 employees using file](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aemployee-file-program) — Object Oriented Programming, chapter 8
