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

  • Home
  • SEARCH
  • 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 6071997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:06:40+00:00 2026-05-23T10:06:40+00:00

This is my First post on StackOverFlow. I was working on linklist – below

  • 0

This is my First post on StackOverFlow.
I was working on linklist – below is my code.
I am just adding a single node to list and printing it — All I am doing is passing a pointer to the “addTermNode” function and then pointing this passed pointer to the newly created Node.

#include<stdio.h>
#include<time.h>


typedef struct _termination_code_ {
  int terminationCode;
  unsigned long time;
  struct _termination_code_ *next;
}termination_code;

int addTermCode(termination_code *infoTerm, int termCode, unsigned long timerInfo)
{
        termination_code *node;
        node=(termination_code*)malloc(sizeof(termination_code));
        if(NULL == node) return -1;
        node->terminationCode=termCode;
        node->time=timerInfo; 
        node->next=NULL;
        infoTerm = node;
        return 0;
}

int main ()
{
        termination_code *list2=NULL;
        //Add A single node and print it. 
        if(addTermCode(list2, 12, time(0))==0)
                printf("All OK node added\n");
        else 
                printf("something went wrong\n");

        printf("Entered info :%d %ld\n",list2->terminationCode,list2->time);
}

Here what I get the output — Not sure why. Please Help.

[zahmed@build3 rnd]$ ./a.out 
All OK node added
Segmentation fault
[zahmed@build3 rnd]$ 

Thanks

  • 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-23T10:06:40+00:00Added an answer on May 23, 2026 at 10:06 am

    The problem is the way you are passing back the new object. Assigning the new object to the pointer will not work the way you have it written. You should return the object instead from your addTermCode() function.

    Basically your list2 pointer is still null. Return the newly created object from that function and assign it to list2.

    If not, you’ll need to adjust your code so that the pointer is properly assigned.

    int addTermCode(termination_code **infoTerm, int termCode, unsigned long timerInfo)
    {
         ....
         *infoTerm = node;
    }
    
    int main ()
    {
        termination_code *list2=NULL;
        //Add A single node and print it.
        if(addTermCode(&list2, 12, time(0))==0)
           printf("All OK node added\n");
        printf("Entered info :%d %ld\n",list2->terminationCode,list2->time);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first post here on stackoverflow and am very impressed by the
This is my first post on Stack Overflow and I'm just wondering on the
This is my first post to stackoverflow, so bear with me. :) I am
This is my first post on stackoverflow, hello everyone! My first venture into jQuery
this is my first post on stackoverflow, I hope you can help me out!
This is my first post on StackOverflow. This community has provided me with some
Hey everyone, this is my first post up on StackOverflow! WOO! Anyhow, onto my
This is my first post on StackOverflow, so please be gentle... I have some
This is my first post on stackoverflow, I hope one of many! My question
this is my first post on stackoverflow. Hopefully I am not disturbing anybody... :)

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.