Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7445177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:45:31+00:00 2026-05-29T11:45:31+00:00

I need to create a linked list in my program. In my program the

  • 0

I need to create a linked list in my program. In my program the list is allocated on the heap with malloc(), than i try to visit it but i get a segmetation fault;

EDIT: i get the SIGSEGV at this line “while(!(node->nodeType == TYPE_END_LIST)){“

    struct dagNode *createList(int k);
    struct dagNode *newNodeXInterval(int type, int val);


    struct dagNode *createList(int k){
    struct dagNode *head, *node;
    printf("\nList %d = ", k);
    head = newNodeXInterval(TYPE_EDGE_OR_GAP, getVal(k,1));
    node = head;
    int i;
    for (i=1; i<LENGTH_OF(k); i++){
            node->next = newNodeXInterval(TYPE_XTEST, getRightPointOf(k,i));
            node = node->next;
            node->next = newNodeXInterval(TYPE_EDGE_OR_GAP, getVal(k,i+1));
            node = node->next;
            }     
    node = newNodeXInterval(TYPE_END_LIST, 0);
    node = head;     // i think that here there is the error
    printf("%d", node->val); i=0;
                    while(!(node->nodeType == TYPE_END_LIST)){
                        printf("%d ", i);
                        node = node->next;}
    return head;}


    struct dagNode *newNodeXInterval(int type, int val){
        struct dagNode *node = (struct dagNode *) malloc(sizeof(struct dagNode));
        if (type == TYPE_EDGE_OR_GAP){
        *node = (struct dagNode) {(val<0)? TYPE_GAP:TYPE_EDGE, val, NULL, NULL, NULL};
        }
        else{
        *node = (struct dagNode) {type, val, NULL, NULL, NULL};
        }
        return node;    }

The caller function would get the head of the list.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:45:33+00:00Added an answer on May 29, 2026 at 11:45 am

    As far as I can tell, the problem is with the line

    node = newNodeXInterval(TYPE_END_LIST, 0);
    

    Before the assignement, node points to the last node in your linked list, and the previous node has its next pointer equal to node. After the assignement, node points to the newly created node with type TYPE_END_LIST, but the previous node has its next pointer unchanged (i.e. it still holds the original value of node). In other words, your newly created node is not a part of the list, and thus the condition node->nodeType == TYPE_END_LIST in the following while() loop will never evaluate to true, and you’ll end up dereferencing a null pointer when you go past the end of the list. Changing the line to

    node->next = newNodeXInterval(TYPE_END_LIST,0);     
    

    should fix the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a Linked List from a text file that looks like
[SOLVED] So I decided to try and create a sorted doubly linked skip list...
I've already created the Binary Tree and Linked list classes, I'm just in need
I need to create a linked server to a DB2 database on a mainframe.
i need create an email list sending to many emails. what is best solution
I need to create a 2D int array of size 800x800. But doing so
I've written my own linked-list type data structure, and would like to create an
I'm studying C++ on my own time, and writing a linked list to try
Say that I need to create 3 linked lists one for int, one for
How can I create a list in C++? I need it to create a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.