Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using recursion to output to file

Status
Not open for further replies.

KT927

Programmer
Oct 1, 2000
5
0
0
US
I'm using recursion to output array to text file. Thanks for the help.

Here is code. I'm only getting the last number in the text file. What do I need to fix?

KT

File_Array_Recurs(int Array[], int size)
{
ofstream outi("data4.txt")
if(size>=0)
File_Array_Recurs(Array, size -1);
outi<<Array[size]<<endl;
outi.close();
}
and this is what I had in header file
File_Array_Recurs(int[], int);

Driver File
File_Array_Recurs(Array, size -1);

[sig][/sig]
 
I would have to understand the way your file is setup , rescusion is nice, but it's not nessary when your array can be output sequencially, also every time you open a new file stream you start right back at the beginning, try opening the stream prior to calling the rescursion, I still feel you can acomplish this feat very simpily with just a do while loop, since it has no tree like structure to worry about, for example I have a Multiple Print Query page, that creates a tree of choices, with parent children, recursion comes in extremly handy when calling each node, then calling again to see if it has children, and pops up then goes back down the next, yours simple goes down, and comes back up once, but no need to actually use recursion the way you have it written. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top