piscine/r01/ex00/main.c
Willem Haffmans 607ce08c18 all
2024-09-10 00:18:01 +02:00

73 lines
1.8 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/15 16:56:20 by whaffman #+# #+# */
/* Updated: 2024/06/16 14:09:57 by whaffman ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include <stdlib.h>
int **allocate_array(int r, int c);
int solve(int *cond, int **grid, int row);
int char_to_int(char c)
{
return (c - '0');
}
int ft_split_string(char *str, int *arguments, int n)
{
int count;
count = 0;
while (count < n)
{
if (*str >= '1' && *str <= '4')
{
arguments[count] = char_to_int(*str);
str ++;
count ++;
}
else
return (0);
if (count == n && *str == '\0')
return (1);
if (count == n && *str == ' ')
return (0);
if (*str == ' ')
str ++;
else
return (0);
}
return (1);
}
//int cond[] = {3, 2, 1, 2, 1, 2, 2, 3, 3, 2, 2, 1, 2, 1, 2, 3};
int main(int argc, char *argv[])
{
int **grid;
int conditions[16];
if (argc != 2)
{
write(1, "Error\n", 6);
return (0);
}
if (!ft_split_string(argv[1], &conditions[0], 16))
{
write(1, "Error\n", 6);
return (0);
}
grid = allocate_array(4, 4);
if (!solve(&conditions[0], grid, 0))
write(1, "Error\n", 6);
free(grid);
return (0);
}