Listing 1. Doubly Linked List Template
/*
* Template for using the doubly linked list.
* The dll_dbg.h header is not actually used in
* the code below; however, this could be one way
* that a debugging version could be implemented.
* For a more complete example of how to use the
* doubly linked list refer to the documentation
* and source code in the distribution package.
*/
#include <stdio.h>
#include <stdlib.h>
#ifdef DEBUG
# include <dll_dbg.h> /* For debug only */
#else
# include <linklist.h> /* For production */
#endif
typedef struct name_addr /* Sample data
* structure */
{
char name[30];
char street[40];
char city[22];
char state[3];
char zip[11];
} NameAddr;
void main(void)
{
List *NAList = NULL;
DLL_Return DLL_Exit;
if(DLL_CreateList(&NAList) == NULL)
{
fputs("Fatal Memory error", stderr);
exit(EXIT_FAILURE);
}
if((DLL_Exit = DLL_InitializeList(NAList,
sizeof(NameAddr)))
!= DLL_NORMAL)
{
(void)(DLL_Exit == DLL_ZERO_INFO
&& fputs(
"Size of address record is zero.\n\n", stderr));
(void)(DLL_Exit == DLL_NULL_LIST
&& fputs(
"NAList points to a NULL address.\n\n", stderr));
exit(EXIT_FAILURE);
}
DoYourThingHere(NAList);
DLL_DestroyList(&NAList);
exit(EXIT_SUCCESS);
}
Copyright © 1994 - 2018 Linux Journal. All rights reserved.