#include <stdio.h>
#include <stdlib.h>
struct Person
{
char surname[50];
unsigned int age;
struct Person *descendants;
unsigned int descendantsCount;
};
void zrobPotomka(struct Person *parent, unsigned int howMany)
{
parent->descendants = (struct Person*) malloc(howMany * sizeof(struct Person));
parent->descendantsCount = howMany;
for (int offset = 0; offset < howMany; offset++)
{
struct Person *currentDescendant = parent->descendants + offset;
strcpy(currentDescendant->surname, parent->surname);
currentDescendant->age = 0;
}
}
void printPersonData(struct Person *person)
{
printf("Nazwisko: %s, Wiek: %d, ilość potomków: %d \n", person->surname, person->age, person->descendantsCount);
//printf("Wiek: %d, ilość potomków: %d \n", person->age, person->descendantsCount);
for (int cnt = 0; cnt < person->descendantsCount; cnt++)
{
printf("Potomek %d:", cnt + 1);
struct Person *descendant = person->descendants + cnt;
printPersonData(descendant);
}
}
void createPersons(struct Person** persons, int idx, const char surname[25], unsigned int age, int surnameLong)
{
persons[idx] = (struct Person*)malloc(sizeof(struct Person));
persons[idx]->age = age;
memcpy(persons[idx]->surname, surname, surnameLong);
}
int main()
{
struct Person** osoby;
char w;
int size,i=0;
int idx,idxArray[size];
printf("podaj ile chcesz stworzyc osob");
scanf("%d", &size);
osoby = (struct Person*) malloc(size * sizeof(struct Person));
while (i < size)
{
printf("podaj jaką opcje wybierasz \n");
printf("a --- utwórz strukture pod wybranym indeksem \n");
printf("p --- wypisz wszystkie dane z tablicy \n");
printf("c --- utworz potomkow na bazie osoby \n");
scanf("%c", &w);
switch (w)
{
case 'a':
break;
case 'c':
zrobPotomka(&osoby, size-1);
break;
case 'p':
break;
}
i++;
}
printPersonData(&osoby);
printPersonData(&osoby);
return 0;
}