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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:07:24+00:00 2026-05-31T12:07:24+00:00

Trying to take in several file names from the user at the command line

  • 0

Trying to take in several file names from the user at the command line and store them into a linked list, but I’m receiving a segmentation fault. The idea is to have the user enter each file name then enter ‘q’ when they’re finished.

I enter in the first file name, “man_on_moon.txt” and no error occurs. After I enter the second, “sat_moons_rings.txt” I get.. Segmentation fault: 11
I believe it’s occurring in my assignment to char *name, but am not sure.

char *name = malloc(sizeof(char) *50);
scanf("%s", name);
list *curr, *head;
curr = malloc(sizeof(list));
head = malloc(sizeof(head));
if(name != "q")
{
    curr->item = name;
    head->next = curr;
    curr = curr->next;
    scanf("%s", name);
}
while(name != "q")
{
    curr->item = name;
    curr = curr->next;
    scanf("%s", name);
}
  • 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-31T12:07:25+00:00Added an answer on May 31, 2026 at 12:07 pm

    You never set curr->next to anything so it’s pointing to NULL then you set curr to curr->next. Therefore when you get into the while loop you access curr->item you are trying to get the fields of NULL and you get a segfault.

    The reason behind this is you are only mallocing space for 2 nodes. You have malloc space for every node you make.

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

Sidebar

Related Questions

I am trying to take a rather large CSV file and insert it into
When a user loads a project file into my application it can take a
I am trying to take several RSS feeds, and put the content of them
I have several checkboxes and I am trying to take a lazy approach of
I am trying to take two numbers and get the square of them. Using
I'm trying to take a stream of data from standard in, compress it one
So I'm basically just trying to take in some file input, and then take
I am trying to take a folder that has several .csv files in it
I am trying to take a data string from one column and split it
I have a datagridview with 9 columns. I am simply trying take the value

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.