95 lines
2.2 KiB
C
95 lines
2.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* init_tables.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: psalame <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/07/22 19:12:44 by psalame #+# #+# */
|
|
/* Updated: 2023/07/23 17:44:52 by psalame ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <stdlib.h>
|
|
|
|
int get_area_size(void);
|
|
|
|
int **get_row_args(char **argv)
|
|
{
|
|
int i_row;
|
|
int tab_index;
|
|
int **row;
|
|
int s;
|
|
|
|
s = get_area_size();
|
|
row = malloc(s * sizeof(int *));
|
|
if (row == NULL)
|
|
return (NULL);
|
|
i_row = s * 4;
|
|
tab_index = 0;
|
|
while (i_row < (s * 6 - 1))
|
|
{
|
|
if (argv[1][i_row] != ' ')
|
|
{
|
|
row[tab_index] = malloc(2 * sizeof(int));
|
|
row[tab_index][0] = argv[1][i_row] - '0';
|
|
row[tab_index][1] = argv[1][i_row + s * 2] - '0';
|
|
tab_index ++;
|
|
}
|
|
i_row ++;
|
|
}
|
|
return (row);
|
|
}
|
|
|
|
int **get_col_args(char **argv)
|
|
{
|
|
int i_col;
|
|
int tab_index;
|
|
int **col;
|
|
int s;
|
|
|
|
s = get_area_size();
|
|
col = (int **) malloc(s * sizeof(int *));
|
|
if (col == NULL)
|
|
return (NULL);
|
|
i_col = 0;
|
|
tab_index = 0;
|
|
while (i_col < (s * 2 - 1))
|
|
{
|
|
if (argv[1][i_col] != ' ')
|
|
{
|
|
col[tab_index] = malloc(2 * sizeof(int));
|
|
col[tab_index][0] = argv[1][i_col] - '0';
|
|
col[tab_index][1] = argv[1][i_col + s * 2] - '0';
|
|
tab_index++;
|
|
}
|
|
i_col ++;
|
|
}
|
|
return (col);
|
|
}
|
|
|
|
int **init_res(void)
|
|
{
|
|
int i;
|
|
int j;
|
|
int **res;
|
|
|
|
res = malloc(get_area_size() * sizeof(int *));
|
|
if (res == NULL)
|
|
return (NULL);
|
|
i = 0;
|
|
j = 0;
|
|
while (i < get_area_size())
|
|
{
|
|
res[i] = malloc(get_area_size() * sizeof(int));
|
|
j = 0;
|
|
while (j < get_area_size())
|
|
{
|
|
res[i][j] = 0;
|
|
j++;
|
|
}
|
|
i++;
|
|
}
|
|
return (res);
|
|
}
|