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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:31:10+00:00 2026-06-02T16:31:10+00:00

I’ve been trying to add a new node into a linked list of profiles

  • 0

I’ve been trying to add a new node into a linked list of profiles (for ex. facebook profiles), and I’m getting a runtime error while launching. This is what I got :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>

typedef struct friend {
    char *name;
    int age;
    char gender;
    struct friend* next;
} friend;

void node_add(friend* new);

int main(int argc, char *argv[]) {
    friend amit;
    friend *new;

    amit.name = "amit";
    amit.age = 16;
    amit.gender = 'm';

    node_add(new);
    new->name = "amit";

    printf ("name: %s\n", new->name);
    system("PAUSE");    

    return 0;
}

void node_add(friend* new) {
    new = (friend* )malloc(sizeof(friend));
    friend* head = new;
    new -> next = head;
}

I’m trying now to create a delete node function. I tried to find which node does the user wants to delete, and then delete it by doing

delete -> next = delete -> next -> next

The problem is, I need to get for the first node in the list.
Here is what I wrote:

void node_delete(friend* delete) {
    friend *temp;
    char name[256];
    int i = 0, j = 0;

    printf ("Please enter the friend's name you want to delete: \n");
    fgets (name, 256, stdin);
    fgets (name, 256, stdin);

    while (0 == (strcmp(temp -> next -> name, delete -> next -> name))) {
        temp = friend -> next;
    }
    temp -> next = temp -> next -> next;
    free (delete);
}
  • 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-02T16:31:11+00:00Added an answer on June 2, 2026 at 4:31 pm

    Edit:

    It seems my test was a mite too quick, because there is in fact a pretty serious problem with this code, but it’s subtle:

    In main() you are never actually pointing new at anything. It’s just a garbled pointer out into memory space, which might sometimes work, and most of the time, is just terrible.

    friend *new; // here's your problem; change this to:
    friend *new = malloc(sizeof(friend));
    

    Also, never cast the results of malloc.

    Reedit:

    How a very simple linked list implementation might look:

    typedef struct _node node;
    struct _node {
      void *payload;
      node *next;
    };
    
    node *create_node () {
      node *retval = malloc(sizeof(node));
    
      retval->payload = NULL;
      retval->next = NULL;
    
      return retval;
    }
    
    node *add_node (node *target) {
      if (target->next)
        return;
    
      node *next = create_node();
      node->next = next;
    }
    
    node *node_search (node *haystack, void *needle) {
      while (haystack) {
        if (!compare(needle, haystack->payload)) {
          return haystack;
        } else {
          haystack = haystack->next;
        }
      }
    
      return NULL;
    }
    

    Implementation of deletion and insertion are left as an exercise to the reader.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.