0
Good evening, I would like to know methods to read a string in C(Version C99), I have tried a lot, and does not work, below, the defective code.
Obs: The error that reports is that just after pressing "ENTER" on the first 'gets' of the registration function, the program Buga, and displays the message "the program.exe has stopped working".
Obs.1: I removed the < >
includes as the browser identifies this as an html tag and does not display the contents of includes.
#include stdio.h
#include stdlib.h
int menu()
{
int opc;
printf("\n Opcoes: \n1. Cadastrar livros\n2. Consultar livros\n3. Alterar informacoes de livros\n4. Remover um livro da lista");
scanf("%d", &opc);
return(opc);
}
struct informacoes
{
char nome[100];
char autor[100];
long long int isbn;
char volume[10];
int data;
char editora[100];
int paginas;
};
int cadastro(struct informacoes *livros, int i){
printf("\nNome do livro: ");
gets(livros[i].nome);
printf("\nAutor: ");
gets(livros[i].autor);
printf("\n ISBN : ");
scanf("%lli", livros[i].isbn);
printf("\n Volume em romanos: ");
gets(livros[i].volume);
printf("\n Ano de lancamento: ");
scanf("%d", livros[i].data);
printf("\nEditora do livro: ");
gets(livros[i].editora);
printf("\nQuantidade de paginas no livro: ");
scanf("%d", livros[i].paginas);
}
int main()
{
int opc = menu();
struct informacoes livros[10];
int i=0;
switch(opc)
{
case 1:
cadastro(livros, &i);
}
return (EXIT_SUCCESS);
}
when I messed with C, he’s about 4 years old, or he used gets or scanf, if he tried to use both, stick in the right kkkk
– Rovann Linhalis
I guess that’s not the problem, kkk
– Luiz Campos
Try running the program with a Debugger and see the error that returns.
– Francisco
Appears 1 Warning and 1 note, attachment:
– Luiz Campos
dnvisso. c:44:30: Warning: Passing argument 2 of 'register' makes integer from Pointer without a cast [-Wint-Conversion] register(books, &opc);
– Luiz Campos
dnvisso. c:19:5: note: expected 'int' but argument is of type 'int *' int cadastro(struct informacoes *livros, int i){
– Luiz Campos
The problem is in its parameters, ie the
(struct informacoes *livros, int i)
, I’m trying to figure out why.– Francisco