-
Notifications
You must be signed in to change notification settings - Fork 3
array_list.c
elaine yeung edited this page Apr 12, 2017
·
2 revisions
This page explains the array_list.c program that our shell uses.
Functions in this program are declared in our project specific header.
/**
* arr_size - finds size of array
* @arr: array of pointers to strings
* Return: size of the array
*/
int arr_size(char **arr)
{
int i;
if (arr == NULL || *arr == NULL)
return (-1);
i = 0;
while (arr[i])
i++;
return (i);
}This function takes a pointer to an array of pointers as an argument and returns the size of the array of pointers.
/**
* array_to_list - builds a linked list of array of pointers
* @array: array of pointers to strings
* Return: pointer to head
*/
list_t *array_to_list(char **array)
{
list_t *head;
list_t *new;
int i;
head = NULL;
for (i = 0; array[i] != NULL; i++)
{
new = add_node_end(&head, array[i]);
if (new == NULL)
{
free_list(head);
return (NULL);
}
}
return (head);
}This function takes a pointer to an array of pointers as an argument. It returns a pointer to the head of a linked list.