如何解决在结构指针的next *字段中访问int
我有一个指向Tasks结构的指针,该结构具有三个字段tid,difficulty和next。我想将一个任务中的下一个任务的难度与一个数字进行比较,但是当我尝试以下操作时,我得到了附件错误:
struct Tasks
{
int tid; /*Task's identifier*/
int difficulty; /*Task's difficulty*/
struct Tasks *next; /*Pointer to the next node*/
};
struct Tasks* curr = (*player)->tasks_head->next;
if(curr->next->difficulty < difficulty) {...}
这是我为新节点分配内存的方式:
struct Tasks* node = (struct Tasks*) malloc(sizeof(struct Tasks)); // Could return null if not enough mem
if(node == NULL) return 0;
// add data to the new node
node->tid = tid;
node->difficulty = difficulty;
node->next = NULL;
抛出异常:读取访问冲突。 curr-> next为0xCDCDCDCD
我以为我可以通过执行*(curr->next)->difficulty
来解除对下一个指针的引用,但这不允许我进行编译,我也不明白为什么。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。