Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started