-
Notifications
You must be signed in to change notification settings - Fork 2
/
Array.c
45 lines (35 loc) · 790 Bytes
/
Array.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "includes.h"
#include "Array.h"
void **ArrayAdd(void **Array, void *Item)
{
void *ptr;
int count=0;
if (! Array) Array=calloc(10, sizeof(void *));
else
{
for (ptr=*Array; ptr !=NULL; ptr++)
{
count++;
}
}
Array=realloc(Array, (count+10) * sizeof(void *));
Array[count]=Item;
Array[count+1]=NULL;
return(Array);
}
void *ArrayGetItem(void *array[], int pos)
{
int i;
for (i=0; i <= pos; i++)
{
if (array[i]==NULL) return(NULL);
if (i==pos) return(array[i]);
}
return(NULL);
}
void ArrayDestroy(void **Array, ARRAY_ITEM_DESTROY_FUNC DestroyFunc)
{
void **ptr;
for (ptr=Array; *ptr != NULL; ptr++) DestroyFunc(*ptr);
if (Array != NULL) free(Array);
}