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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:53:01+00:00 2026-06-10T07:53:01+00:00

#include<stdio.h> #include<stdlib.h> struct node { char str[200]; int nn; struct node* next; }; int

  • 0
#include<stdio.h>
#include<stdlib.h>

struct node {
    char str[200];
    int nn;
    struct node* next;
};

int number;
struct node* start=NULL;
struct node* current;
//function to insert into the list 

void insert() {
    struct node* n;
    n=(struct node*)malloc(sizeof(struct node));
    n->str=malloc(sizeof(char) * 1000);
    printf("please enter the data that you would like to insert: ");
    gets(n->str);
    printf("asdasdasdasd");
    n->next=NULL;
    if( start==NULL ) {
        start->next=n;
        current=n;
    }
    else {

    current->next=n;
    current=n;

    }

    printf("done\n");
}

void display() {
    current=start;
    int i=0;
    while( current->next!=NULL ) {
        printf("node%d= %s\n",++i,current->str);
        current=current->next;

    }
    printf("this the end");
}


int main() {
    char c;
    int input;

    do {
        printf("Select from the following options:\n"
           "1.Display list\n"
           "2.Add to list\n"
           "3.delete from list\n");

        scanf("%d",&input);
        switch (input) {
            case 1: display(); break;
            case 2: insert(); break;
      //    case 3: delete(); break;
            default : printf("Please select 1 , 2 or 3\n");
        }
        printf( "would you like to continue?(y/n)\n");
        scanf("%s",&c);
    } while(c=='y');

    return 0;
}

This is giving me an error in the insert function, A SEGMENTATION FAULT !

I Tried things but I just don’t get the clear picture. I am a bit weak with pointers, actually confused !

Please help me out by telling me what I am doing wrong. Forget about my linked list logic, let it be wrong. I just wanna know why a segmentation fault is occurring !

  • 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-10T07:53:02+00:00Added an answer on June 10, 2026 at 7:53 am

    you have many mistakes, but your crash is because you don’t allocate start

    n->next=NULL;
        if( start==NULL ) {
            start->next=n;
            current=n;
        }
        else {
    
        current->next=n;
        current=n;
    

    you ask if start is null, and if it is you try to read it by calling start->next it. you need to allocate it first.

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

Sidebar

Related Questions

#include<stdio.h> #include<stdlib.h> struct node { int data; struct node *next; }; void insert( struct
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { // int char str[40],ch; FILE*fp,*fp1,*fp2; fp=fopen(ide_input,w); fp1=fopen(error_log,w); fp2=fopen(lex_output,w);
#include <stdio.h> #include <stdlib.h> typedef struct { char *Name; int grade; int cost; }Hotel;
This following code works fine: #include <stdio.h> #include <stdlib.h> int main() { struct node{
I have the following C-code: #include<stdio.h> #include<stdlib.h> typedef struct node { int a; }node;
Code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> typedef struct node { char*
#include<stdlib.h> #include<string.h> #include<stdio.h> int pstrcmp( char **p,char **q) { return strcmp(*p,*q) ; } int
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { if(argc != 2) return
In one file I have this: #include <stdio.h> #include <stdlib.h> static struct node* mynode;

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.