当我尝试在两个不同的地方使用相同的函数时,出现了一个非常奇怪的段错误错误。
printTVNode 函数在 main 上运行良好。 在主要部分:
printTVNode(headTVNode); /* Works fine here */
TVNodePointer headTopic = NULL;
TopicEmmissions(&headTopic,headTVNode,desiredTopic);
当我尝试在 TopicEmmissions 函数中使用 printTVNode 时,会出现 Seg 错误。
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*/
...
printTVNode函数:
void printTVNode(TVNodePointer headTVNode){
TVNodePointer currentTVNode = headTVNode;
while ( currentTVNode != NULL ){
printEmmission(*(currentTVNode->anEmmission));
currentTVNode = currentTVNode->next;
}
}
最佳答案
问题似乎出在以下行:
printEmmission(*(currentTVNode->anEmmission));
在 anEmmission
为 NULL
的情况下,当您尝试取消引用它时,我认为您会遇到段错误。
在取消引用之前,请确保检查 anEmmission
不为 NULL
。
关于c - 段错误 :I can't understand why,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29853548/