#include "stdafx.h" #include #include struct Date { int day; int month; int year; }; struct Student { char firstName[20]; char lastName[30]; Date dateOfBirth; }; Student ReadStudent() { Student newStud; printf(" firstName: "); gets_s(newStud.firstName); printf(" lastName: "); gets_s(newStud.lastName); printf(" day: "); scanf("%d", &newStud.dateOfBirth.day); printf(" month: "); scanf("%d", &newStud.dateOfBirth.month); printf(" year: "); scanf("%d", &newStud.dateOfBirth.year); getchar(); return newStud; } void PrintStudent(Student stud) { printf("%s %s (%d-%d-%d)\n", stud.firstName, stud.lastName, stud.dateOfBirth.day, stud.dateOfBirth.month, stud.dateOfBirth.year); } void PrintStudents(Student *arr, int count) { for (int i = 0; i < count; i++) { printf("arr[%d]: ", i); PrintStudent(arr[i]); } } int DisplayMenu() { int num; printf("------ Menu --------\n"); printf("1. Input students array\n"); printf("2. Display students array\n"); printf("3. Search student by birth year\n"); printf("0. Exit\n"); printf("-> "); scanf("%d", &num); return num; } int main() { Student arr[100]; int count; int num; do { num = DisplayMenu(); switch (num) { case 1: printf("Count : "); scanf("%d", &count); getchar(); for (int i = 0; i < count; i++) { printf("--- arr[%d] ---\n", i); arr[i] = ReadStudent(); } break; case 2: PrintStudents(arr, count); case 3: int year; int resCount = 0; printf("Year: "); scanf("%d", &year); for (int i = 0; i < count; i++) if (arr[i].dateOfBirth.year == year) { PrintStudent(arr[i]); resCount++; } if (resCount == 0) printf("...........Message.... \n"); } } while (num != 0); return 0; }