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
+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 */
/* */
/* ************************************************************************** */
+18 -3
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);
}
+18 -15
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,22 +95,24 @@ static char *get_the_line(int fd, char *buffer) {
i = 0;
nb_read = 0;
line = NULL;
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'));
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) {
read_file(fd, buffer, &nb_read);
if (nb_read < 0)
return (free(line), NULL);
if (nb_read == 0)
break;
line = build_line(buffer, line, &i);
ft_memcpy(buffer, buffer + i + 1, ft_strlen_with_c(buffer + i, '\0'));
while (detect_newline(line) == 0)
{
read_file(fd, buffer, &nb_read);
if (nb_read < 0)
return (free(line), NULL);
if (nb_read == 0)
break ;
line = build_line(buffer, line, &i);
ft_memcpy(buffer, buffer + i + 1, ft_strlen_with_c(buffer + i, '\0'));
}
return (line);
return (line);
}
char *get_next_line(int fd) {
+37 -8
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);
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);
}