typedef struct{
int moviesRented;
char title[20][20];
} Movie;
typedef struct{
int accNumber;
char name[20];
Movie movie_rental;
} Customer;
int main(){
int i;
int j;
int customerRecords;
Customer *pCustomer;
printf("Enter amount of customer records to be kept: ");
scanf("%d", &customerRecords);
pCustomer = malloc(customerRecords * sizeof(Customer));
// Начинается запрос ввода данных, относящихся к клиенту.
for(i = 0; i < customerRecords; ++i){
printf("Enter account number, name, and movies rented: \n");
scanf("%d\n %s\n %d", &(pCustomer + i)->accNumber, &(pCustomer +i)->name, &(pCustomer + i)->movie_rental.moviesRented);
// цикл ниже запрашивает несколько названий фильмов в зависимости от того, сколько фильмов было арендовано
for( j = 0; j < (pCustomer+i)->movie_rental.moviesRented; ++j){
//asking for input of movie titles and trying to add into string array
printf("Enter Movie titles: \n");
scanf("%s", &(pCustomer+i)->movie_rental.title[j]);
}
}
printf("Displaying information: \n");
for(i = 0; i < customerRecords; ++i){
printf("Name: %s\nAcc. Number: %d\nNo. Movies Rented: %d\n",(pCustomer+i)->name, (pCustomer+i)->accNumber, (pCustomer+i)->movie_rental.moviesRented);
// для цикла ниже не отображается правильно.Отображает только последнюю запись в первой итерации
for(j = 0; j < (pCustomer+i)->movie_rental.moviesRented; j++){
printf("Movies rented: %s\n", (pCustomer+i)->movie_rental.title[j]);
}
return 0;
}