home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
useful
/
dev
/
c
/
cmanual
/
system
/
lists
/
example3.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-12
|
3KB
|
105 lines
/***********************************************************/
/* */
/* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
/* ------------------------------- ------------------ */
/* */
/* Book: ACM System Amiga C Club */
/* Chapter: Lists Tulevagen 22 */
/* File: Example3.c 181 41 LIDINGO */
/* Author: Anders Bjerin SWEDEN */
/* Date: 92-05-01 */
/* Version: 1.00 */
/* */
/* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
/* */
/* Registered members may use this program freely in their */
/* own commercial/noncommercial programs/articles. */
/* */
/***********************************************************/
/* Demonstrates how to scan through a list looking for */
/* nodes with a special name. Uses the function */
/* FindName(). */
#include <exec/types.h>
#include <exec/lists.h> /* This file will automatically */
/* include the file "nodes.h". */
/* Declare a complete node stucture: */
struct ToDo
{
struct Node node; /* Every node must have this. */
STRPTR Wish; /* Our own data. */
};
/* Declare a list structure: */
struct List my_list;
/* Node 1: */
struct ToDo eat=
{
{ NULL, NULL, NT_UNKNOWN, 0, "Food" },
"eat breakfast"
};
/* Node 2: */
struct ToDo sleep=
{
{ NULL, NULL, NT_UNKNOWN, 0, "Sleep" },
"rest"
};
/* Node 3: */
struct ToDo drink=
{
{ NULL, NULL, NT_UNKNOWN, 0, "Food" },
"drink some nice wine"
};
main()
{
struct Node *node_ptr; /* Node pointer. */
struct ToDo *ptr; /* Pointer to ToDo structures. */
/* Initialize our list structure: */
NewList( &my_list );
/* Add three nodes: */
printf( "Adding some nodes...\n" );
AddTail( &my_list, &eat );
AddTail( &my_list, &sleep );
AddTail( &my_list, &drink );
/* Find the first node that is about Food: */
node_ptr = (struct Node *) FindName( &my_list, "Food" );
/* As long as we find nodes about Food stay in the loop: */
while( node_ptr )
{
/* Copy the address of the node into the DoDo pointer: */
ptr = (struct ToDo *) node_ptr;
/* Print the nodes wish: */
printf( "I want to %s.\n", ptr->Wish );
/* Try to find yet another node about Food: */
/* (Are you getting hungry?) */
node_ptr = (struct Node *) FindName( node_ptr, "Food" );
}
/* Remove all nodes from the list: */
printf( "Remove all nodes...\n" );
RemHead( &my_list, &eat );
RemHead( &my_list, &sleep );
RemHead( &my_list, &drink );
}