i'm trying to make a function that draws a square, but i want to do it recursively, so i'm using a static variable, one problem: my function seg faults when I pass too high parameters to it, so i'm asking you if that is because of the static, or something else, thanks for your help, here's the code:
int square(int x, int y)
{
static t_coord pos;
if (x < 0 || y < 0)
{
ft_puts(2, "Error"); // if the size is negative it displays error on stderr
return (FAILURE);
}
if (!pos.y)
pos.y++;
if (pos.x == x)
{
if (pos.y == y)
return (SUCCESS);
pos.y++;
pos.x = 1;
write(1, "\n", 1);
}
else
pos.x++;
ft_write_case(pos.x, pos.y, x, y); // function to write either corner side or space (middle)
return(square(x, y));
}
the problem doesnt come from my ft_write_case function because i replaced it by a simple write(1, "o", 1) and it did the same segmentation fault, thanks for the help