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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:06:55+00:00 2026-06-05T00:06:55+00:00

The program is supposed to prompt the user for their username. Upon receiving the

  • 0

The program is supposed to prompt the user for their username. Upon receiving the username it concatenates it with ‘.history’ to create username.history. Then it opens that file (username.history) and reads the input from it. I am running into a segfault here though. Whenever it opens the file, which is empty because the file doesn’t exist, it reads multiple lines and then throws the segfault. I think the problem might stem from how I’m trying to open the file, but I’m not sure. Here is the portion that is causing problems:

// File input and output
ifstream f_in;
ofstream f_out;

// Prompt user for their username.
char username[80];
cout << "Please input your username: " << endl;
cin >> username;
cout << endl;
cout << "Loading history file if it exists." << endl;

// Create file naem and initialize the file line counter to 0.
strcat(username, ".history");
int fcount = 0;

// Open file and read in lines if there are any.
// Place read lines into the command string for use later.
char tmp[50];

f_in.open(username);
while(!f_in.eof()){
    f_in >> tmp;
    cmd[fcount] = tmp;
    fcount++;
}
f_in.close();

Other pertinent info:
cmd is declared as a global variable (char cmd[200][50])

Any help will be greatly appreaciated.

  • 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-05T00:06:57+00:00Added an answer on June 5, 2026 at 12:06 am

    Not sure if it is the only issue, but cmd[fcount] = tmp is wrong. You should use strcpy().

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

Sidebar

Related Questions

This is a program that is supposed to prompt user for hours worked and
This is a program that is supposed to prompt the user to enter three
I have a java program that is supposed to run a bat file, and
I am currently making a program which is supposed to prompt the user to
The program is supposed to create x amount of threads based on the arguments
The program is supposed to take a file, say data.dat, filled with a list
I have a program that is supposed to interact with a web server and
I have a small program that's supposed to sample some value from a device
I have recently made a program that is supposed to take two environment variables,
My program is supposed to tally up bottles from 4 rooms. When the user

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.