Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im working on recursion in c++ language and I need help dealing with big text files. I have to open a text file then read

Im working on recursion in c++ language and I need help dealing with big text files. I have to open a text file then read the contents backwords and print the contents on screen or in another txt file going backwards. The problem I am running into is stack overflow my program works on smaller files but as soon as I get a text file near 1000 kb or more my program crashs if their is any way around this Id appreciate the help. Im simply opening the text file storing into string array then calling recursion function with a base case that returns empty if no text is found, otherwise it prints the contents backwords.

Heres my code.

#include  #include  #include  using namespace std; void reverse_file(ifstream &in) { if(!in.eof()) { char ch = in.get(); reverse_file(in); cout << ch; } } int main() { string filename; cout << "Enter file name: "; cin >> filename; ifstream in(filename.c_str()); if(in.is_open()) { reverse_file(in); cout << endl; in.close(); } else { cout << "can not open " << filename << " to read" << endl; } return 0; } 

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

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students also viewed these Databases questions

Question

Develop a program for effectively managing diversity. page 303

Answered: 1 week ago

Question

List the common methods used in selecting human resources. page 239

Answered: 1 week ago