diff --git a/.cache/clangd/index/check_input.c.D27AA41095D26EB5.idx b/.cache/clangd/index/check_input.c.D27AA41095D26EB5.idx index 1710bd2..426188a 100644 Binary files a/.cache/clangd/index/check_input.c.D27AA41095D26EB5.idx and b/.cache/clangd/index/check_input.c.D27AA41095D26EB5.idx differ diff --git a/.cache/clangd/index/game.c.B03695838049B596.idx b/.cache/clangd/index/game.c.B03695838049B596.idx index 4c41481..bdf0cab 100644 Binary files a/.cache/clangd/index/game.c.B03695838049B596.idx and b/.cache/clangd/index/game.c.B03695838049B596.idx differ diff --git a/.cache/clangd/index/main.c.449FC24725B4900F.idx b/.cache/clangd/index/main.c.449FC24725B4900F.idx index 1f7aed8..6aa352d 100644 Binary files a/.cache/clangd/index/main.c.449FC24725B4900F.idx and b/.cache/clangd/index/main.c.449FC24725B4900F.idx differ diff --git a/.cache/clangd/index/vector.c.CCEA61708CF10975.idx b/.cache/clangd/index/vector.c.CCEA61708CF10975.idx index cf16e9d..9acc478 100644 Binary files a/.cache/clangd/index/vector.c.CCEA61708CF10975.idx and b/.cache/clangd/index/vector.c.CCEA61708CF10975.idx differ diff --git a/inc/.cache/clangd/index/alcu.h.FC2EE915F1165072.idx b/inc/.cache/clangd/index/alcu.h.FC2EE915F1165072.idx index 08856db..46cf185 100644 Binary files a/inc/.cache/clangd/index/alcu.h.FC2EE915F1165072.idx and b/inc/.cache/clangd/index/alcu.h.FC2EE915F1165072.idx differ diff --git a/src/check_input.c b/src/check_input.c index 18516cb..bc75835 100644 --- a/src/check_input.c +++ b/src/check_input.c @@ -32,7 +32,7 @@ bool check_input(t_vector* lines) line = (char*)lines->pfVectorGet(lines, j); i = -1; while (line[++i]) - if (!(line[i] >= '0' && line[i] <= '9') && line[i] != '\n') + if ((!(line[i] >= '0' && line[i] <= '9') && line[i] != '\n') || i > 5) return (false); if (ft_atoi(line) < 1 || ft_atoi(line) > 10000) return (false); diff --git a/src/fill_vector.c b/src/fill_vector.c index 13666f5..e8c830c 100644 --- a/src/fill_vector.c +++ b/src/fill_vector.c @@ -6,7 +6,7 @@ /* By: lud-adam +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/03/28 13:21:46 by lud-adam #+# #+# */ -/* Updated: 2026/03/29 14:58:09 by lud-adam ### ########.fr */ +/* Updated: 2026/03/29 16:31:19 by lud-adam ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/main.c b/src/main.c index 3ff6c79..1499304 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: lud-adam +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/03/28 12:30:29 by lud-adam #+# #+# */ -/* Updated: 2026/03/29 14:58:10 by lud-adam ### ########.fr */ +/* Updated: 2026/03/29 16:31:17 by lud-adam ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,9 +51,6 @@ int main(int argc, char *argv[]) return (1); } - if (argc == 1) - fd = open("/dev/tty", O_RDONLY); - // // fd = get_fd(argc, argv); lines_int = fill_array(&lines, &size); if (!lines_int) { diff --git a/src/vector.c b/src/vector.c index ef4bc91..08769ee 100644 --- a/src/vector.c +++ b/src/vector.c @@ -13,26 +13,25 @@ #include "vector.h" #include "libft.h" #include +#include -int vectorResize(t_vector *v, int capacity); -int vectorPushBack(t_vector *v, void *item); -int vectorSet(t_vector *v, int index, void *item); -void *vectorGet(t_vector *v, int index); -int vectorDelete(t_vector *v, int index); -int vectorFree(t_vector *v); -int vectorTotal(t_vector *v); +int vector_resize(t_vector *v, int capacity); +int vector_push_back(t_vector *v, void *item); +int vector_set(t_vector *v, int index, void *item); +void *vector_get(t_vector *v, int index); +int vector_delete(t_vector *v, int index); +int vector_free(t_vector *v); +int vector_total(t_vector *v); void vector_init(t_vector *v) { - // Initialize function pointers - v->pfVectorTotal = vectorTotal; - v->pfVectorResize = vectorResize; - v->pfVectorAdd = vectorPushBack; - v->pfVectorSet = vectorSet; - v->pfVectorGet = vectorGet; - v->pfVectorFree = vectorFree; - v->pfVectorDelete = vectorDelete; - // Allocate memory and check for failure + v->pfVectorTotal = vector_total; + v->pfVectorResize = vector_resize; + v->pfVectorAdd = vector_push_back; + v->pfVectorSet = vector_set; + v->pfVectorGet = vector_get; + v->pfVectorFree = vector_free; + v->pfVectorDelete = vector_delete; v->vector_list.capacity = VECTOR_INIT_CAPACITY; v->vector_list.total = 0; v->vector_list.items = malloc(sizeof(void *) * v->vector_list.capacity); @@ -43,7 +42,7 @@ void vector_init(t_vector *v) } } -int vectorTotal(t_vector *v) +int vector_total(t_vector *v) { int totalCount = UNDEFINE; if(v) @@ -53,30 +52,34 @@ int vectorTotal(t_vector *v) return totalCount; } -int vectorResize(t_vector *v, int capacity) +int vector_resize(t_vector *v, int capacity) { int status = UNDEFINE; if(v) { - void **items = realloc(v->vector_list.items, sizeof(void *) * capacity); - if (items) + void **items_copy = malloc(sizeof(void *) * capacity); + if (!items_copy) + return (status); + ft_memcpy(items_copy, v->vector_list.items, sizeof(void *) * v->pfVectorTotal(v)); + if (items_copy) { - v->vector_list.items = items; + free(v->vector_list.items); + v->vector_list.items = items_copy; v->vector_list.capacity = capacity; status = SUCCESS; } } - return status; + return (status); } -int vectorPushBack(t_vector *v, void *item) +int vector_push_back(t_vector *v, void *item) { int status = UNDEFINE; if(v) { if (v->vector_list.capacity == v->vector_list.total) { - status = vectorResize(v, v->vector_list.capacity * 2); + status = vector_resize(v, v->vector_list.capacity * 2); if(status != UNDEFINE) { v->vector_list.items[v->vector_list.total++] = item; @@ -91,7 +94,7 @@ int vectorPushBack(t_vector *v, void *item) return status; } -int vectorSet(t_vector *v, int index, void *item) +int vector_set(t_vector *v, int index, void *item) { int status = UNDEFINE; if(v) @@ -105,7 +108,7 @@ int vectorSet(t_vector *v, int index, void *item) return status; } -void *vectorGet(t_vector *v, int index) +void *vector_get(t_vector *v, int index) { void *readData = NULL; if(v) @@ -118,7 +121,7 @@ void *vectorGet(t_vector *v, int index) return readData; } -int vectorDelete(t_vector *v, int index) +int vector_delete(t_vector *v, int index) { int status = UNDEFINE; int i = 0; @@ -135,17 +138,17 @@ int vectorDelete(t_vector *v, int index) v->vector_list.total--; if ((v->vector_list.total > 0) && ((v->vector_list.total) == (v->vector_list.capacity / 4))) { - vectorResize(v, v->vector_list.capacity / 2); + vector_resize(v, v->vector_list.capacity / 2); } status = SUCCESS; } return status; } -int vectorFree(t_vector *v) +int vector_free(t_vector *v) { - int status = UNDEFINE; - int total = v->pfVectorTotal(v); + int status = UNDEFINE; + int total = v->pfVectorTotal(v); if(v) { for (int i = 0; i < total; i++)