So, if i change buf[t_index] to *buf(got a before & after below), and do buf++ instead of t_index++, i get a segmentation fault, what's the cause of this? my study requires limited function lines, and i have 1 too many =[.
BEFORE:
t_tetrimino *ft_sort_list(char **buf, int x, int y, int block)
{
t_tetrimino *curr;
t_tetrimino *head;
int t_index;
int index;
index = 0;
t_index = 0;
curr = (t_tetrimino*)malloc(sizeof(t_tetrimino));
head = curr;
while (buf[t_index] != NULL)
{
if (ft_validator(buf[t_index], 0, 0, 0) == -1)
return (NULL);
while (buf[t_index][index])
{
if (buf[t_index][index] == '#')
(curr->x[block] = x) && (curr->y[block] = y) && block++;
buf[t_index][index] == '\n' && index != 19 ? (y++ && (x = 0)) : x++;
index++;
}
set_tetr_properties(&curr);
reset_vars(&block, &x, &y, &index);
t_index++;
}
return (head);
}
WHAT I WANT:
t_tetrimino *ft_sort_list(char **buf, int x, int y, int block)
{
t_tetrimino *curr;
t_tetrimino *head;
int t_index;
int index;
index = 0;
t_index = 0;
curr = (t_tetrimino*)malloc(sizeof(t_tetrimino));
head = curr;
while (*buf != NULL)
{
if (ft_validator(*buf, 0, 0, 0) == -1)
return (NULL);
while (*buf[index])
{
if (*buf[index] == '#')
(curr->x[block] = x) && (curr->y[block] = y) && block++;
*buf[index] == '\n' && index != 19 ? (y++ && (x = 0)) : x++;
index++;
}
set_tetr_properties(&curr);
reset_vars(&block, &x, &y, &index);
buf++;
}
return (head);
}