因此,如果我将buf [t_index]更改为* buf(在下面的之前和之后得到一个),并且使用buf ++而不是t_index ++,则会出现分段错误,这是什么原因造成的?我的研究要求功能线有限,并且我有1个太多= [。
之前:
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);
}
我想要的是
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);
}