Error declaration null - Unknown type name 'bool'

4

The error you are giving is in this function.

bool tem_numero_na_lista(tipo_lista * aux, int valor) {
  while (aux - > prox != NULL) {
    if (aux - > info == valor) {
      return true;
    }
    aux = aux - > prox;
    else {
      return false;
    }
  }
}
  

error: unknown type name 'bool'

    
asked by anonymous 18.04.2017 / 16:31

2 answers

1

Beyond the error: unknown type name 'bool' | has some other minor function errors

while (aux -> prox != NULL)

You 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 traversed and the value not found, just put the return after 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 lista with values entered, you can test like this:

Ex: Verify that the 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);
    
18.04.2017 / 21:37
5

You added #include <stdbool.h> ? Are you using a compiler that is at least compatible with C99? Needs.

This code has other problems.

Documentation .

    
18.04.2017 / 16:35