加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C中的棘手段错误

发布时间:2020-12-16 10:10:35 所属栏目:百科 来源:网络整理
导读:我正在尝试为我的大学任务运行一个C项目,并且我在以下代码段中的“while(current- next!= NULL){”行中遇到了一个seg错误: FILE* f = fileOpen("test.txt");if (f != NULL){ functionList = fileReadToMemory(f,graphParams);//functionList is a pointer
我正在尝试为我的大学任务运行一个C项目,并且我在以下代码段中的“while(current-> next!= NULL){”行中遇到了一个seg错误:

FILE* f = fileOpen("test.txt");
if (f != NULL){
    functionList = fileReadToMemory(f,&graphParams);//functionList is a pointer to the first value of the linked list it creates
    current = functionList;

    while (current->next != NULL) {
        printf("%d %d %d %s",current->red,current->green,current->blue,current->expression);//Prints value of linked list
        current = current -> next;
    }
}

gdb给我的错误如下:

Program received signal EXC_BAD_ACCESS,Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x000000000000003a
0x0000000100000b30 in main () at main.c:23
23          while (current->next != NULL) {

我究竟做错了什么?

提前致谢!

解决方法

你需要这样做

while (current != NULL)

代替

current->next != NULL

因为列表中的最后一个元素会导致段错误.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读