In addition to error: Unknown type name 'bool'| has some other minor errors in function
while (aux -> prox != NULL)
Will not check the last item in the list.
else {
return false;
}
The else
is not necessary, to return false
if the list has been searched and the value not found, just put the return after the while
.
bool tem_numero_na_lista(tipo_lista * aux, int valor) {
while (aux != NULL) {
if (aux -> info == valor) {
return true;
}
aux = aux -> prox;
}
return false;
}
Already having a lista
with the entered values, you can test like this:
Ex: Check if number 7 is in the list.
int valor = 7;
if( tem_numero_na_lista(lista, valor) )
printf("Encontrou o valor %d na lista", valor);
else
printf("Não encontrou o valor %d na lista", valor);
you included
#include <stdbool.h>
?– Marconi