gpt4 book ai didi

c - 段错误 :I can't understand why

转载 作者:太空宇宙 更新时间:2023-11-03 23:24:48 27 4
gpt4 key购买 nike

当我尝试在两个不同的地方使用相同的函数时,我遇到了一个非常奇怪的段错误。

printTVNode 函数在 main 上工作正常。在主要方面:

printTVNode(headTVNode); /* Works fine here */

TVNodePointer headTopic = NULL;
TopicEmmissions(&headTopic,headTVNode,desiredTopic);

当我尝试在 TopicEmmissions 函数中使用 printTVNode 时,会出现 get Seg Fault。

void TopicEmmissions(TVNodePointer * headTopic,TVNodePointer headTVNode,char * desiredTopic){
TVNodePointer currentTVNode = headTVNode;
EmmissionPointer currentEmmission;
EventPointer currentEvent;
EventPointer topicSubjects = NULL;
int flag,countEvent = 1,countEmmission = 1;

printTVNode(headTVNode); /* Get Segmentation Fault here*/
...

打印电视节点函数:

void printTVNode(TVNodePointer headTVNode){
TVNodePointer currentTVNode = headTVNode;

while ( currentTVNode != NULL ){
printEmmission(*(currentTVNode->anEmmission));

currentTVNode = currentTVNode->next;
}
}

最佳答案

问题似乎出在以下行:

printEmmission(*(currentTVNode->anEmmission));

anEmmissionNULL 的情况下,当您尝试取消引用它时,我认为您会遇到段错误。

确保在取消引用之前检查 anEmmission 不是 NULL

关于c - 段错误 :I can't understand why,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29853548/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com