mirror of
https://github.com/LucasCodeur/alcu.git
synced 2026-04-28 17:44:34 +02:00
solve merge
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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
@@ -6,7 +6,7 @@
|
|||||||
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/03/28 13:27:29 by lud-adam #+# #+# */
|
/* 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);
|
char *read_file(int fd);
|
||||||
int check_input(int fd);
|
int check_input(int fd);
|
||||||
void print_board(int *game_state, size_t nb_line);
|
void print_board(int *game_state, size_t nb_line);
|
||||||
|
int *fill_array(int fd, int size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+5
-3
@@ -6,18 +6,20 @@
|
|||||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/11/05 11:17:31 by dgaillet #+# #+# */
|
/* 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"
|
#include "libft.h"
|
||||||
|
|
||||||
size_t ft_strlen(const char *s)
|
size_t ft_strlen(char *str, char c)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (s[i])
|
if (!str)
|
||||||
|
return (0);
|
||||||
|
while (str[i] && str[i] != c)
|
||||||
i++;
|
i++;
|
||||||
return (i);
|
return (i);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
|
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/03/28 13:01:37 by dgaillet #+# #+# */
|
/* 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
@@ -6,13 +6,28 @@
|
|||||||
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/03/28 13:21:46 by lud-adam #+# #+# */
|
/* 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 "../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);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-4
@@ -6,11 +6,12 @@
|
|||||||
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/03/28 15:07:17 by lud-adam #+# #+# */
|
/* 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 "get_next_line.h"
|
||||||
|
|
||||||
#include "../libft/libft.h"
|
#include "../libft/libft.h"
|
||||||
|
|
||||||
size_t ft_strlen_with_c(char *str, char c) {
|
size_t ft_strlen_with_c(char *str, char c) {
|
||||||
@@ -94,18 +95,20 @@ static char *get_the_line(int fd, char *buffer) {
|
|||||||
i = 0;
|
i = 0;
|
||||||
nb_read = 0;
|
nb_read = 0;
|
||||||
line = NULL;
|
line = NULL;
|
||||||
if (buffer[0] != '\0') {
|
if (buffer[0] != '\0')
|
||||||
|
{
|
||||||
line = build_line(buffer, NULL, &i);
|
line = build_line(buffer, NULL, &i);
|
||||||
if (!line)
|
if (!line)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
ft_memcpy(buffer, buffer + i + 1, ft_strlen_with_c(buffer + i, '\0'));
|
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);
|
read_file(fd, buffer, &nb_read);
|
||||||
if (nb_read < 0)
|
if (nb_read < 0)
|
||||||
return (free(line), NULL);
|
return (free(line), NULL);
|
||||||
if (nb_read == 0)
|
if (nb_read == 0)
|
||||||
break;
|
break ;
|
||||||
line = build_line(buffer, line, &i);
|
line = build_line(buffer, line, &i);
|
||||||
ft_memcpy(buffer, buffer + i + 1, ft_strlen_with_c(buffer + i, '\0'));
|
ft_memcpy(buffer, buffer + i + 1, ft_strlen_with_c(buffer + i, '\0'));
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-8
@@ -6,7 +6,7 @@
|
|||||||
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
/* By: lud-adam <lud-adam@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/03/28 12:30:29 by lud-adam #+# #+# */
|
/* 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 "../libft/libft.h"
|
||||||
#include "alcu.h"
|
#include "alcu.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[])
|
||||||
if (argc != 2) {
|
{
|
||||||
|
if (argc != 2)
|
||||||
|
{
|
||||||
ft_putstr_fd("ERROR", 2);
|
ft_putstr_fd("ERROR", 2);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = open(argv[1], O_RDONLY);
|
int fd = open(argv[1], O_RDONLY);
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1)
|
||||||
|
{
|
||||||
ft_putstr_fd("ERROR", 2);
|
ft_putstr_fd("ERROR", 2);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = check_input(fd);
|
int size = check_input(fd);
|
||||||
printf("size %d\n", size);
|
printf("size %d\n", size);
|
||||||
if (size < 0) {
|
if (size < 0)
|
||||||
|
{
|
||||||
ft_putstr_fd("ERROR", 2);
|
ft_putstr_fd("ERROR", 2);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
int test[] = {8, 5, 3, 2, 1};
|
if (size < 0)
|
||||||
print_board(test, 5);
|
{
|
||||||
return (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);
|
close(fd);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user