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???
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.
programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.