From d6ca938a34c1a034a4275c61e27de68d046a7a81 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Fri, 5 Apr 2024 10:07:59 +0200 Subject: [PATCH] Add function for filling a matrix --- Makefile | 1 + ft_arr/ft_mat_fill.c | 33 +++++++++++++++++++++++++++++++++ inc/ft_arr.h | 3 ++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 ft_arr/ft_mat_fill.c diff --git a/Makefile b/Makefile index b5f287f..b33312e 100644 --- a/Makefile +++ b/Makefile @@ -106,6 +106,7 @@ SRCarr := ft_vec_init.c \ ft_mat_insert_col.c \ ft_mat_insert_row.c \ ft_mat_zeros.c \ + ft_mat_fill.c \ ft_mat_access.c \ ft_mat_free.c \ diff --git a/ft_arr/ft_mat_fill.c b/ft_arr/ft_mat_fill.c new file mode 100644 index 0000000..b8bc4e9 --- /dev/null +++ b/ft_arr/ft_mat_fill.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_mat_fill.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/05 10:00:33 by ljiriste #+# #+# */ +/* Updated: 2024/04/05 10:07:19 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_arr.h" +#include "libft.h" + +t_arr_stat ft_mat_fill(t_mat *mat, void *filler) +{ + size_t i; + size_t j; + + i = 0; + while (i < mat->cols) + { + j = 0; + while (j < mat->rows) + { + ft_memcpy(ft_mat_access(mat, i, j), filler, mat->vec.el_size); + ++j; + } + ++i; + } + return (success); +} diff --git a/inc/ft_arr.h b/inc/ft_arr.h index bc9bcb1..f4389db 100644 --- a/inc/ft_arr.h +++ b/inc/ft_arr.h @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/09 13:58:15 by ljiriste #+# #+# */ -/* Updated: 2024/04/02 11:13:24 by ljiriste ### ########.fr */ +/* Updated: 2024/04/05 10:05:22 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -93,5 +93,6 @@ t_arr_stat ft_mat_erase_cols(t_mat *mat, size_t count, size_t index, void (*free_el)(void *)); void *ft_mat_access(t_mat *mat, size_t row, size_t col); t_arr_stat ft_mat_zeros(t_mat *matrix, size_t rows, size_t cols); +t_arr_stat ft_mat_fill(t_mat *mat, void *filler); #endif -- 2.30.2