#include #include #include struct date { int year; int month; int day; }; typedef struct { struct date birth; char name[10]; } person; char *vowels = "aeiou"; char random_consonant() { for (;;) { char letter = 'a' + rand() % 26; if (!strchr(vowels, letter)) return letter; } } char random_vowel() { return vowels[rand() % strlen(vowels)]; } char *random_name() { static char buf[9]; memset(buf, 0, 9); for (size_t i = 0; i < 4; i++) { buf[i*2] = random_consonant(); buf[i*2+1] = random_vowel(); } buf[0] -= 'a' - 'A'; return buf; } void generate(person people[], int n) { for (size_t i = 0; i < n; i++) { people[i].birth.year = 1900 + rand() % 123; people[i].birth.month = rand() % 12 + 1; people[i].birth.day = rand() % 28 + 1; strcpy(people[i].name, random_name()); } } void print_person(person people[], int i) { printf("%s born %02d-%02d-%04d\n", people[i].name, people[i].birth.day, people[i].birth.month, people[i].birth.year); } void print_people(person people[], int n) { for (size_t i = 0; i < n; i++) { print_person(people, i); } } int main() { person people[3]; generate(people, 3); print_people(people, 3); return 0; }