The program should be able to read a file and reverse all the words inside, using recursive function.
This is my entire code. DO not bother about the main I know it is working
Do not bother with function" void OpenFile(const char *fileName, ifstream &inFile); " it is working
Do not bother with function " bool CheckIfCharIsASeparator(char charToCompare)" it is working
Do not bother with function " int Reverse(ifstream &inFile, int level)" it is working
I have a question though on function " int ReverseRecursively(char *tempLine, ofstream &MyDestinationFile) " that is being called by function " int Reverse(ifstream &inFile, int level)" .
TestFile2.txt contains these two lines
Text :is a, not: a number;
The big, brown , fox jumps! over? the lazy dog .
I read the character one at a time and.
when I reached a space ( where my pointer is pointing) I need to save that location but I am not allowed to use any static variables.the reason I wanted to save it is because as soon as I see a separator I go back and empty the stack and thus accomplish your first requirement which is to reverse the word. But in doing so my pointer also goes back to the first position before I called the recursive function.
So I ended up with "txeT txeT txeT txeT txeT".
When emptying the stack how can I keep the value of the pointer on that first space after the word "Text"?
THIS IS THE WHOLE PROGRAM SOMEHOW IT IS NOT DOING WHAT I WANT IT TO DO.
#include <cstdlib>
#include <fstream>
#include <iostream>
using namespace std;
const char * const FILENAME = "TestFile2.txt";
void OpenFile(const char *fileName, ifstream &inFile);
int Reverse(ifstream &inFile, int level);
//This function will just open the input file for processing
void OpenFile(const char *fileName, ifstream &inFile)
{
inFile.open(fileName, ios::in);
if(!inFile.is_open())
{
cout << cerr << " OPEN FILE " << fileName << " FAILED \n";
cout << " FILE WILL NOT OPEN: RETURN TO EXIT";
cin.get();
exit(EXIT_FAILURE);
}
}