#include #include typedef struct tree { char name[20]; struct tree* next; } tree; /* We choose a new type name "tree" same as the tag, but we could use myTree here or anything else */ int checktree (tree *p, char aTreeName[]) { int found = 0; while (p != NULL) { if (strcmp(p -> name, aTreeName) == 0) found = 1; p = p -> next; } return (found); } int main (void) { /* declaring variables to hold tree nodes */ tree tree1, tree2, tree3, tree4; char treeName[11]; /* declaring the starting and traveling pointers */ tree *start; /* putting tree names into each node */ strcpy (tree1.name, "Maple"); strcpy (tree2.name, "Fir"); strcpy (tree3.name, "Pine"); strcpy (tree4.name, "Oak"); /* setting the start of the list at tree1 */ start = &tree1; /* linking the other trees together */ tree1.next = &tree2; tree2.next = &tree3; tree3.next = &tree4; /* sets tree4 as the last node of the list */ tree4.next = NULL; /* checking if a tree is in the list */ printf ("Enter tree name to search: "); // gets(treeName); /* do not use "gets" function - Why ? */ fgets (treeName,10,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); }