solve merge

This commit is contained in:
LucasCodeur
2026-03-28 17:05:20 +01:00
parent 7140a17dab
commit 13dc0341fa
14 changed files with 134 additions and 31 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+53
View File
@@ -0,0 +1,53 @@
[
{
"directory": "/home/lud-adam/Documents/rush",
"arguments": [
"cc",
"-Wall",
"-Wextra",
"-Werror",
"-MMD",
"-I",
"inc/",
"-c",
"src/main.c",
"-o",
".obj/main.o"
],
"file": "src/main.c"
},
{
"directory": "/home/lud-adam/Documents/rush",
"arguments": [
"cc",
"-Wall",
"-Wextra",
"-Werror",
"-MMD",
"-I",
"inc/",
"-c",
"src/fill_array.c",
"-o",
".obj/fill_array.o"
],
"file": "src/fill_array.c"
},
{
"directory": "/home/lud-adam/Documents/rush",
"arguments": [
"cc",
"-Wall",
"-Wextra",
"-Werror",
"-MMD",
"-I",
"inc/",
"-c",
"src/check_input.c",
"-o",
".obj/check_input.o"
],
"file": "src/check_input.c"
}
]
+2 -1
View File
@@ -6,7 +6,7 @@
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/28 13:27:29 by lud-adam #+# #+# */
/* Updated: 2026/03/28 13:29:45 by lud-adam ### ########.fr */
/* Updated: 2026/03/28 15:26:01 by lud-adam ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,5 +18,6 @@
char *read_file(int fd);
int check_input(int fd);
void print_board(int *game_state, size_t nb_line);
int *fill_array(int fd, int size);
#endif
+5 -3
View File
@@ -6,18 +6,20 @@
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 11:17:31 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:36:18 by dgaillet ### ########lyon.fr */
/* Updated: 2026/03/28 14:47:54 by lud-adam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlen(const char *s)
size_t ft_strlen(char *str, char c)
{
size_t i;
i = 0;
while (s[i])
if (!str)
return (0);
while (str[i] && str[i] != c)
i++;
return (i);
}
+1 -1
View File
@@ -6,7 +6,7 @@
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/28 13:01:37 by dgaillet #+# #+# */
/* Updated: 2026/03/28 15:14:49 by lud-adam ### ########.fr */
/* Updated: 2026/03/28 16:05:37 by lud-adam ### ########.fr */
/* */
/* ************************************************************************** */
+17 -2
View File
@@ -6,13 +6,28 @@
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/28 13:21:46 by lud-adam #+# #+# */
/* Updated: 2026/03/28 14:02:21 by lud-adam ### ########.fr */
/* Updated: 2026/03/28 16:05:46 by lud-adam ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft/libft.h"
#include "get_next_line.h"
void fill_array(char* file)
int* fill_array(int fd, int size)
{
int* res = malloc(sizeof(int) * size);
if (res == NULL)
return (NULL);
char* line = get_next_line(fd);
int i = 0;
while (line != NULL)
{
res[i] = ft_atoi(line);
i++;
free(line);
line = get_next_line(fd);
}
return (res);
}
+6 -3
View File
@@ -6,11 +6,12 @@
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/28 15:07:17 by lud-adam #+# #+# */
/* Updated: 2026/03/28 15:13:54 by lud-adam ### ########.fr */
/* Updated: 2026/03/28 16:04:59 by lud-adam ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
#include "../libft/libft.h"
size_t ft_strlen_with_c(char *str, char c) {
@@ -94,13 +95,15 @@ static char *get_the_line(int fd, char *buffer) {
i = 0;
nb_read = 0;
line = NULL;
if (buffer[0] != '\0') {
if (buffer[0] != '\0')
{
line = build_line(buffer, NULL, &i);
if (!line)
return (NULL);
ft_memcpy(buffer, buffer + i + 1, ft_strlen_with_c(buffer + i, '\0'));
}
while (detect_newline(line) == 0) {
while (detect_newline(line) == 0)
{
read_file(fd, buffer, &nb_read);
if (nb_read < 0)
return (free(line), NULL);
+38 -9
View File
@@ -6,7 +6,7 @@
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/28 12:30:29 by lud-adam #+# #+# */
/* Updated: 2026/03/28 15:07:41 by lud-adam ### ########.fr */
/* Updated: 2026/03/28 16:06:09 by lud-adam ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,27 +17,56 @@
#include "../libft/libft.h"
#include "alcu.h"
int main(int argc, char *argv[]) {
if (argc != 2) {
int main(int argc, char *argv[])
{
if (argc != 2)
{
ft_putstr_fd("ERROR", 2);
return (1);
}
int fd = open(argv[1], O_RDONLY);
if (fd == -1) {
if (fd == -1)
{
ft_putstr_fd("ERROR", 2);
return (1);
}
int size = check_input(fd);
printf("size %d\n", size);
if (size < 0) {
if (size < 0)
{
ft_putstr_fd("ERROR", 2);
return (1);
}
int test[] = {8, 5, 3, 2, 1};
print_board(test, 5);
return (0);
close(fd);
if (size < 0)
{
ft_putstr_fd("ERROR", 2);
return (1);
}
int* lines = fill_array(fd, size);
if (!lines)
return (1);
for (int i = 0; i < size; i++)
{
char buffer[100] = "";
ft_putstr_fd("Player : ", 1);
char* temp = ft_itoa(i % 2 == 0 ? 1 : 2);
ft_putstr_fd(temp, 1);
ft_putstr_fd("\n", 1);
ft_putstr_fd("Enter the number of matchs to take off: ", 1);
int nb_read = read(0, buffer, sizeof(buffer));
if (nb_read > 0)
{
int temp = ft_atoi(buffer);
if (temp > 1 && temp < 4)
lines[i] -= temp;
else
ft_putstr_fd("Between 1 and 3", fd);
print_board(lines, 5);
}
}
close(fd);
return (0);
}