Need help searching a linked list. This is what I have so far but I am not sure if the while loop is correct. I also am unsure if the code is completely correct. Any help would be appreciated.
//structure for writing to and reading from file**
struct filebook
{
int code;
char title[20];
char author[20];
int pages;
}ebook;
//************************************************
//structure for creating the linked list**********
struct book
{
int code;
char title[20];
char author[20];
int pages;
struct book*next;
}*head,*work,*node,*previous,*found,libry;
void search(void)
{
system("cls");
printf ("\t\t\tTusket Municipal Library\n\n\n");
printf("Which book code do you want to search for?: ");
scanf("%d",&libry.code);
printf("\n");
if(libry.code=&libry.code)
{
found=libry.code;
}
while(found != NULL && found->next!= found) //DO NOT reverse condition
{
previous=found;
found=found->next;
}
if (found == NULL)
{
printf("Sorry, not in the list.");
printf("\n");
getch();
main_menu();
}
else
{
printf("Your book has been found in the list.");
printf("\n");
getch();
main_menu();
}
}
We are searching by code.