ListCreate

ListType ListCreate (int itemSize);

Purpose

This function creates a list that holds items of the specified size.

Parameters

Input
Name Type Description
itemSize integer Pass the size in bytes of the items that the list will hold.

For example, to create a list of doubles:

#include "toolbox.h"
{

double value1 = 5.0;
double value2 = 7.0;
ListType newList;

newList = ListCreate(sizeof(double));

if (newList)

{
ListInsertItem(newList, &value1, END_OF_LIST);
ListInsertItem(newList, &value2, END_OF_LIST);
}

}


The size of every item in the list must be the same. If you want to have a list of items that can be different sizes, make a list of pointers to the items instead.

For example, to make a list of strings:

#include "toolbox.h"
{

char *dog = "dog";
char *cat = "cat";
ListType newList;

newList = ListCreate(sizeof(char *));

if (newList)

{
ListInsertItem(newList, &dog, END_OF_LIST);
ListInsertItem(newList, &cat, END_OF_LIST);
}

}

Return Value

Name Type Description
newList ListType Returns a new empty list.

If there is not enough memory, zero (0) is returned.