Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following program is in c++ ; I am trying to read in games from a file and when doing so I am only reading

The following program is in c++ ; I am trying to read in games from a file and when doing so I am only reading in parts of the file. It is giving me a segmentation fault error I am going to post my code below if anyone is able to help me debug the program I would greatly appreciate it. The program is too large to be submitted as a single question on here :(

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

void Business::addGamesFromFile() { ifstream infile; string file; char line[100]; Game* newGame; Text* gName; Text* gDescription; float gCost; int gPlayers; int gOccupancy; float gDuration; cout << "Enter the file name: "; cin >> file; infile.open(file.c_str()); if(infile.good()) { cout << "Your file has been opened." << endl; infile.getline(line, 100); cout << line << endl; while(!infile.eof()) { gName = new Text(line); infile.getline(line, 100); cout << line; gDescription = new Text(line); infile >> gCost; cout << gCost << endl; infile >> gPlayers; cout << gPlayers << endl; infile >> gOccupancy; cout << gOccupancy << endl; infile >> gDuration; cout << gDuration << endl; newGame = new Game(gName, gDescription, gCost, gPlayers, gOccupancy, gDuration); gameArray[numGames] = newGame; numGames++; infile.getline(line, 100); } } else { cout << " No file" << endl; } }

----------------------------------------------------------------------------------

void Business::addItemsFromFile() { ifstream infile; string file; char line[100]; RentItem* newItem; Text* iName; Text* iDescription; float iCost; int iStock; float iDuration; cout << "Enter file name: "; cin >> file; infile.open(file.c_str()); if(infile.is_open()) { infile.getline(line, 100); while(!infile.eof()) { iName = new Text(line); infile.getline(line, 100); iDescription = new Text(line); infile >> iCost; infile >> iStock; infile >> iDuration; newItem = new RentItem(iName, iDescription, iCost, iStock, iDuration); rentItemArray[numRentItems] = newItem; numRentItems++; infile.getline(line, 100); } } else { cout << " No file" << endl; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions