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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending Output to File

Status
Not open for further replies.

Mungovan

Programmer
Oct 24, 2002
94
IE
Hi.
Basically I have a program that loops through the output and sends it to the screen. Now I need to output the results to a file. How do I go about doing this???

I'm using MS Visual C on Windows NT.

Anywho, thanks a million,
D
 
you didn't mention what kind of output... however, I'm assuming that if you are "catching" it to be able to display it on screen, you have the text available to stick in a text file. Perhaps you may be better off using the [tt]fputs()[/tt] ANSI C function like this:

[tt]FILE* f = fopen("outputfile.txt","a+");
if (f==NULL) return;
while(..in loop get each line in a buffer..)
{
fputs(outputLine,f);
}
fflush(f);
fclose(f);[/tt]

The bits I've highlighted should be implemented by you. You need to determine the number of lines for output or whatever way of controlling the loop.
The variable [tt]outputLine[/tt] is your string to output. Don't forget to tack a newline character on the end of each line if you want.

This file is opened in appending mode - you could also use "w" (write) mode if you are not worried about destroying the previous contents of the file from a prior output. Both wways will create the file first if it doesn't already exist.

:)
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top