c - 为什么我的指针没有增加到下一个索引?
问题描述
所以,如果我将 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);
}
解决方案
推荐阅读
- reactjs - Electron、React 和 electron-redux - 无法解析“fs”
- java - 如何在 Config 文件中实现 SpringBoot 中 JavascriptExecutor 的通用方法?
- scala - 无法在集群中运行 Kafka Producer 应用程序 JAR 文件(基于 scala)
- transactions - NFT 智能合约,随着时间的推移不断添加 NFT。每次添加都必须花费汽油吗?
- excel - 暂时关闭 Excel 备份
- bash - 如何将 SHELL 重新更改为默认 bash 而不是 zsh
- android - Cupertino 图标未显示在 android 设备上
- html - 防止所选值在 POST/提交后重置
- opencv - 在 conda 环境中在 jetson xavier NX 上构建带有 Gstreamer 支持的 opencv
- r - 如何在R中的数据框中添加一列?