1
Hello! I am a computer science student and I am developing a library program with menu. The program works all that is a beauty by exception of one thing...
When I do a search by author I cannot place when the author was not found when I add Else it finds the author and then appears not found for each book registered.
could help me?
follows my search code
case 'a':
fflush(stdin);
printf("\ndigite o AUTOR do livro que procura\n");
gets(autor_pesquisa);
for(i=0; i<=cadlivrosmax; i++){
retorno = strcmp(autor_pesquisa,quantidades[i].autor);
if(retorno == 0){
printf("Codigo: %d\n",i+1);
printf("Titulo: %s\n",quantidades[i].titulo);
printf("Autor: %s\n",quantidades[i].autor);
printf("Estilo: %s\n",quantidades[i].estilo);
printf("Preco: %f\n\n\n",quantidades[i].preco);
}
else{
printf("\n autor não encontrado\n");
}
}
break;
Note that your
if
is inside the loop. One possibility is you break the loop when you find it and at the end of the loop test whether or not you found it.– anonimo