|
libft
|
Functions for working with pointer arrays (char**, void**, etc.). More...
Files | |
| file | ft_array.c |
| Implementation of pointer and integer array utilities. | |
| file | ft_array.h |
| Utility functions for handling pointer and integer arrays. | |
Functions | |
| size_t | ft_arraysize (void **array) |
| Returns the number of elements in a NULL-terminated array. | |
| char ** | ft_copy_strarray (char **array) |
| Creates a deep copy of a NULL-terminated string array. | |
| void | ft_free_array (void **array) |
| Frees a NULL-terminated array. | |
| void | ft_free_array_size (void **array, size_t size) |
| Frees an array of pointers with a known size. | |
| bool | ft_is_array_sorted (const int *array, size_t size) |
| Checks if an array of integers is sorted in ascending order. | |
| int | ft_putintarray (int *array, int size) |
| Prints an array of integers to standard output. | |
Functions for working with pointer arrays (char**, void**, etc.).
Includes functions for:
This group includes:
| size_t ft_arraysize | ( | void ** | array | ) |
#include <include/ft_array.h>
Returns the number of elements in a NULL-terminated array.
Calculates the number of elements in a NULL-terminated array.
| array | The array of pointers (NULL-terminated). |
This function iterates over a pointer array (usually a char ** or similar) and returns the number of non-NULL elements until it hits the terminating NULL.
| array | A NULL-terminated array of pointers. |
ft_split, or an environment variable array. | char ** ft_copy_strarray | ( | char ** | array | ) |
#include <include/ft_array.h>
Creates a deep copy of a NULL-terminated string array.
| array | The original string array to copy. |
Allocates a new array of strings and duplicates each string from the input array using ft_strdup. If any allocation fails, all previously allocated strings are freed and NULL is returned.
| array | A NULL-terminated array of strings (char **). |
ft_free_array to avoid memory leaks.| void ft_free_array | ( | void ** | array | ) |
#include <include/ft_array.h>
Frees a NULL-terminated array.
Frees a NULL-terminated array of pointers.
| array | The array to free. |
Iterates through the array and frees each non-NULL element, then frees the array itself.
| array | A NULL-terminated array of dynamically allocated pointers. |
ft_split or ft_copy_strarray to release memory. | void ft_free_array_size | ( | void ** | array, |
| size_t | size | ||
| ) |
#include <include/ft_array.h>
Frees an array of pointers with a known size.
Frees a pointer array of known size.
| array | The array to free. |
| size | Number of elements in the array. |
Frees each non-NULL element of the array up to the given size, then frees the array itself.
| array | An array of dynamically allocated pointers. |
| size | The number of elements to free (not including a terminator). |
| bool ft_is_array_sorted | ( | const int * | array, |
| size_t | size | ||
| ) |
#include <include/ft_array.h>
Checks if an array of integers is sorted in ascending order.
Checks if an integer array is sorted in ascending order.
| array | The array to check. |
| size | Number of elements in the array. |
| array | The array to check. |
| size | The number of elements in the array. |
| int ft_putintarray | ( | int * | array, |
| int | size | ||
| ) |
#include <include/ft_array.h>
Prints an array of integers to standard output.
Prints an integer array to standard output.
| array | The array to print. |
| size | Number of elements. |
Each integer is printed using ft_printf followed by a space, except the last element. The function returns the total number of characters printed.
| array | A pointer to an array of integers. |
| size | The number of elements in the array. |
ft_printf fails.array is NULL or size <= 0, the function returns 0.