Congratulations to AcaCandy on her 100,000th post!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot bsod computer connection crash css dell display drive driver drivers email error ethernet excel firefox firefox 3 game hard drive internet internet explorer itunes laptop linux malware monitor network networking nvidia outlook outlook 2003 outlook 2007 outlook express partition problem router slow software sound trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Change default out stream in C


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
Regicide's Avatar
Senior Member with 302 posts.
 
Join Date: Aug 2003
Experience: Advanced
20-Jan-2005, 03:07 PM #1
Change default out stream in C
I am writting a program in C to take input from the user and depeneding on that output the results to either a file and/or the screen. So, my question was is there a way to change the default out stream for printf()? I know that I could use fprintf to write to files. I want to just change the stream, then use a universal funtion to write to the desired medium.
__________________
When you give everything and the feeling is gone
All the giving is fake, did you fake enough?
When you take everything and you stay too long
When there's nothing left, did you take enough?
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
22-Jan-2005, 06:44 AM #2
printf() AFAIK doesn't handle files streams, but fprintf() handles both so you could do it like this:

Code:
#include <stdio.h>

int main() {
    fprintf(stdout,"\nHello World!\n");
    FILE * pfile;
    pfile = fopen("anexample.txt","w");
    fprintf(pfile,"a line of text");
    fclose(pfile);
    return 0;
}
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 04:12 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.