Я работаю над функцией bool, которая возвращает true, если найдено число в связанном списке, и false, если нет, к сожалению, этот код генерирует ошибку
ОШИБКА:
contains.c:24:1: error: элемент управления может достичь конца непустой функции [-Werror,-Wreturn-type] } ^ 1 сгенерирована ошибка.
Код:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define SIZE 10
//make a struct called node
typedef struct nodes{
int n;
struct nodes* next;
}node;
//initiate a pointer to the node type
node* head=NULL;
//search function
bool search(int number){
//traverse the list
for(node* conductor=head;conductor!=NULL;conductor=conductor->next){
if(conductor->n==number){
return true;
exit(0);
}
return false;
}
}
//main function
int main(void){
//make the linked list
for(int i=0;i<SIZE;i++){
node* new=malloc(sizeof(node));
if(new==NULL){
exit(0);
}
//initiate the new node
new->n=i;
new->next=head;
head=new;
}
printf("The linked list is ready\n");
printf("Please enter the number you are looking for:\n");
int number;
scanf("%i",&number);
if(search(number)){
printf("found\n");
}
else{
printf("Sorry, not found in the list. The list only contains:\n");
}
//printing the list components
for(node* conductor=head;conductor!=NULL;conductor=conductor->next){
printf("%i ",conductor->n);
}
printf("\n");
return 0;
}
так я и не понял где ошибка?