Hi I have to do a program using recursion.
I have 4 .txt files
the first file F.txt has this: 1 2 3 4 $ A 5 6 $ B 7
the second file A.txt includes: 7 9 8 $ C
the third file B.txt includes: 9 8 4
the last file C.txt includes: 0 4 6
My homework is that I have to do a recursive program in C++ that read these files and print every character in it. However, before I print it I have to check to see if there is a $ (dollar sign) and if there is a dollar sign I do not have to print, I have to called the print function that takes as a argument the name of the file.
This will be the output of the program
1 2 3 4 7 9 8 0 4 6 5 6 9 8 4 7
Can someone show me the whole process of the program .cpp file?
Thanks for your help
I will by no means actually write this program but this could be a possible approach.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
string recursive( string stringFromFile );
int main()
{
//open the first file and read the file into a signle string
cout << recursive( stringFromFile );
}
//remove and return items from left side of string
//open a file when $ comes about and insert string
//stop when you dont have any more characters to process
string recursive( string stringFromFile )
{
}
It seems that you need to write a function that is re-entrant, iterates through each character, prints it if not a $, when it hits dollar sign, it calls itself using the character that follows as the filename in its arg list. When each re-entrant call hits EOF, it returns to the caller. I am not going to supply the code since the first step is to always think out the algorithm. File pointer will be local to each recursive call and upon returning will be positioned on the next appropriate char.