#include <stdio.h>
#include <string.h>
#define NL 20
typedef struct tree
{
char tree_name [NL];
struct tree* next;
}tree;
int
checktree (tree *p, char name[])
{
int found = 0;
while (p != NULL)
{
if (strcmp(p -> tree_name, name) == 0)
found = 1;
p = p -> next;
}
return (found);
}
int
main (void)
{
tree tree1, tree2, tree3, tree4;
tree *p, *start;
char treename[NL];
strcpy (tree1.tree_name, "Maple");
strcpy (tree2.tree_name, "Fir");
strcpy (tree3.tree_name, "Pine");
strcpy (tree4.tree_name, "Oak");
start = &tree1;
tree1.next = &tree2;
tree2.next = &tree3;
tree3.next = &tree4;
tree4.next = NULL;
printf ("Enter tree name to search: ");
fgets (treename,sizeof(treename),stdin);
treename[strlen(treename)-1] = '\0';
if (checktree(start, treename))
printf ("%s was found in our list of trees.\n", treename);
else
printf ("%s was not found in our list of trees.\n", treename);
return (0);
}