PDA

View Full Version : [SOLVED] printf into a file



roololing
July 29th, 2011, 08:30 PM
Is there a way to make printf print into a file instead of stdout? I've never worked with files before in c/c++, just robots.... A simple helloworld code would be appreciated.

cguy
July 29th, 2011, 08:36 PM
Use fprintf.

eg:
FILE *fp; /*then open the file*/
char *name="John";
fprintf(fp, "Hello, %s!", name)

roololing
July 29th, 2011, 09:04 PM
Thank you for the quick reply!

stchman
July 30th, 2011, 09:03 AM
I gather we can assume you are programming in C?