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 8844853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:35:25+00:00 2026-06-14T11:35:25+00:00

I am having trouble with linked lists in C, I have only done data

  • 0

I am having trouble with linked lists in C, I have only done data structures such as this in c++.

Gdb is giving me a

Program received signal SIGSEGV, Segmentation fault.
0x0804a23c in addArg (base=0x1, argument=0x804e410 "is") at myshell.c:42
42 while ( (curr != NULL) && (curr->n != NULL) )

I am familiar with segmentation faults having to do with memory, however I thought I have allocated memory correctly. What am I doing wrong?

addArg is being called as addArg(currentCmd->args, lexeme);and currentCmd is a pointer to a node struct

struct lnode {
 char *x;
 struct lnode *n;
};


struct node
  {
    char *command;
    struct lnode *args;
    int input;
    int output;
    int error;
    char *in;
    char *out;
    char *err;
    struct node *next;
    struct node *prev;
  };



void addArg(struct lnode *base, char *argument)
 {
 struct lnode *curr = base;

//this is line 42
  while ( (curr != NULL) && (curr->n != NULL) )
    curr = curr->n;

   curr -> n = malloc(sizeof(struct lnode));
   curr = curr->n;
   curr->x = strdup(argument);
   curr->n = NULL;
 }




struct node* createNode(char *command_, int input_, int output_, int error_, char *in_, char *out_, char *err_, struct node *prev_)
  {
  struct node *n;
  n = malloc(sizeof (struct node));
  n->command = strdup(command_);
  n->prev = prev_;
  n->next = NULL;
  n->input = input_;
  n->output = output_;
  n->error = error_;
  n->in = in_;
  n->out = out_;
  n->err = err_;
  n->args=malloc(sizeof(struct lnode));

 return n;
  }
  • 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-06-14T11:35:26+00:00Added an answer on June 14, 2026 at 11:35 am

    I solved this issue by making the lnode *args into lnode args and making the required changes to memory managment.

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

Sidebar

Related Questions

Im currently having trouble trying to understand linked lists. I have some code that
I am having trouble getting my datasource linked to my repeater through this code
I'm having trouble reversing my doublely linked deque list (with only a back sentinel)
I'm having trouble modifying members of a linked list. We have a struct record
I'm having trouble implementing a Stack using a linked list with struct. The program
So i'm having trouble figuring how to overcome this. Take for example, i have
I am having trouble printing out individual Strings from Interable object. I have this
Hey guys Im attempting to sort a linked list and having trouble with this
Having trouble framing this assertion in Rspec for my rails app. A User has
Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder

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.