There are several problems in the code presented.
%c
is to read a caretere. To read a string you must use %s
- The declaration of a variable of the structure type
struct informacao_sobre_os_filme;
lost the variable name.
- The structure must be declared before the
main
how is convention and so can used by various functions.
Fixing all this would be like this:
struct informacao_sobre_os_filme {
int ano_de_lancamento, faixa_etaria;
double duracao;
char nacionalidade[200], nome_do_filme[200], genero[200];
};
int main(){
struct informacao_sobre_os_filme filme1; //agora variavel chamada filme1
printf("CADASTRMENTO DE FILMES: \n");
printf("Nome do filme: \n");
scanf("%s", filme1.nome_do_filme); //ler para o filme1 no campo nome_do_filme
return 0;
}
Notice that like the nome_do_filme
is an array of characters, is already technically a pointer to the first, so it does not take the &
in the scanf
.
If you want you can even use a more robust form of reading that would be with the fgets
. With fgets
can read more than one word and ensure that it does not read more than the space it allocated, which would be in this case are 200
characters:
...
printf("Nome do filme: \n");
fgets(filme1.nome_do_filme, 200, stdin);
...