-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from jackoske/fix
fixxing memory managment and also exit builtin
- Loading branch information
Showing
12 changed files
with
173 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: Jskehan <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/11/19 17:37:54 by iverniho #+# #+# */ | ||
/* Updated: 2024/07/09 12:13:08 by Jskehan ### ########.fr */ | ||
/* Updated: 2024/08/05 15:06:13 by Jskehan ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -80,7 +80,7 @@ int ft_print_2d_array_fd(char **array, int fd); | |
void ft_free_2d_array(char ***array); | ||
void ft_copy_2d_array_i(char ***dest, char **src, int index); | ||
char **ft_duplicate_2d_array(char **array); | ||
char **ft_add_row_2d_array(char **array, char *row); | ||
char **ft_add_row_2d_array(char **array, char *row, int free_row); | ||
char **ft_add_row_2d_array_i(char ***out, char *row, int i); | ||
char **ft_splice_2d_array(char **dest, char **src, int i); | ||
char **ft_realloc_2d_array(char **array, int new_size); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,13 @@ | |
/* By: Jskehan <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/05/28 17:06:28 by Jskehan #+# #+# */ | ||
/* Updated: 2024/06/07 16:49:39 by Jskehan ### ########.fr */ | ||
/* Updated: 2024/08/05 15:05:42 by Jskehan ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "libft.h" | ||
|
||
|
||
/** | ||
* Function: ft_add_row_2d_array | ||
* ----------------------------- | ||
|
@@ -24,33 +25,57 @@ | |
* | ||
* Note: The array must be NULL-terminated. | ||
*/ | ||
char **ft_add_row_2d_array(char **array, char *row) | ||
#include "libft.h" | ||
|
||
/** | ||
* Function: ft_add_row_2d_array | ||
* ----------------------------- | ||
* Adds a row to a 2D array. | ||
* | ||
* @param array: A pointer to a 2D array. | ||
* @param row: The row to add. | ||
* @param free_row: A flag indicating whether to free the row after adding. | ||
* | ||
* @return: The new 2D array with the added row. | ||
* | ||
* Note: The array must be NULL-terminated. | ||
*/ | ||
char **ft_add_row_2d_array(char **array, char *row, int free_row) | ||
{ | ||
int i; | ||
char **new_array; | ||
|
||
i = 0; | ||
if (!row) | ||
return (array); | ||
if (!array) | ||
{ | ||
new_array = ft_calloc(2, sizeof(char *)); | ||
if (!new_array) | ||
return (NULL); | ||
new_array[0] = ft_strdup(row); | ||
new_array[1] = NULL; | ||
return (new_array); | ||
} | ||
while (array[i]) | ||
i++; | ||
new_array = ft_calloc(i + 2, sizeof(char *)); | ||
if (!new_array) | ||
return (NULL); | ||
i = -1; | ||
while (array[++i]) | ||
new_array[i] = ft_strdup(array[i]); | ||
new_array[i] = ft_strdup(row); | ||
new_array[i + 1] = NULL; | ||
ft_free_2d_array(&array); | ||
return (new_array); | ||
int i; | ||
char **new_array; | ||
|
||
if (!row) | ||
return array; | ||
|
||
if (!array) | ||
{ | ||
new_array = ft_calloc(2, sizeof(char *)); | ||
if (!new_array) | ||
return NULL; | ||
new_array[0] = ft_strdup(row); | ||
new_array[1] = NULL; | ||
if (free_row) | ||
free(row); | ||
return new_array; | ||
} | ||
|
||
for (i = 0; array[i]; i++) | ||
; | ||
|
||
new_array = ft_calloc(i + 2, sizeof(char *)); | ||
if (!new_array) | ||
return NULL; | ||
|
||
for (i = 0; array[i]; i++) | ||
new_array[i] = ft_strdup(array[i]); | ||
|
||
new_array[i] = ft_strdup(row); | ||
if (free_row) | ||
free(row); | ||
|
||
new_array[i + 1] = NULL; | ||
|
||
ft_free_2d_array(&array); | ||
return new_array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.