0
statement and code:
Make a program that stores movies produced by various directors and: - Create and read a vector of 5 directors, each containing name (maximum 20 letters), number of movies and movies. The member films is a vector, which must be created after having read the amount of movies. Each film is composed by name, year and duration. - Find a director by name, showing all the films he has ever produced. Repeat the process until you enter an empty string.
#define QTD 2
typedef struct diretor {
    char nome[20], **filme;
    int qtd;
} DIRETOR;
int main() {
    setlocale(LC_ALL,"portuguese");
    DIRETOR diretor[QTD];
    char busca[20];
    for (int i=0; i<QTD; i++) {
        printf("Nome do diretor: ");
        fflush(stdin);
        fgets(diretor[i].nome, 20, stdin);
        diretor[i].nome[strlen(diretor[i].nome) -1] = '\0';
        printf("Quantidade de filmes: ");
        fflush(stdin);
        scanf("%d", &diretor[i].qtd);
        while (isalpha(diretor[i].qtd) != 0) {
           printf("Entre com um número válido.\n");
           printf("Quantidade de filmes: ");
            fflush(stdin);
            scanf("%d", &diretor[i].qtd);
       }
       diretor[i].filme = (char **) malloc(sizeof(DIRETOR) * diretor[i].qtd);
        for (int l=0; l<QTD; l++) diretor[i].filme[i] = (char*) malloc (20 * sizeof(DIRETOR));
        for (int j=0; j<diretor[i].qtd; j++) {
            printf("Filme %d:", j+1);
            fflush(stdin);
            fgets(diretor[i].filme[j], 20, stdin);
            diretor[i].filme[j][strlen(diretor[i].filme[j]) -1] = '\0';
        }
        printf("\n");
    }
    do {
        printf("Diretor que deseja buscar: ");
        fflush(stdin);
        fgets(busca, 20, stdin);
        busca[strlen(busca) -1] = '\0';
        for (int i=0; i<QTD; i++) {
            if (strcmpi(busca, diretor[i].nome) == 0 && strcmp(busca , "") != 0) {
                printf("Filmes:\n");
                for(int j=0; j<diretor[i].qtd; j++)
                    printf("%s\n", diretor[i].filme[j]);
            }
        }
    } while (strcmp(busca , "") != 0) ;
}
my doubt is: I’m allocating the matrix correctly?
because it doesn’t work when I try to put more than 2 movies in the same director! from now on, thank you