This page has been designed specifically for the printed screen. It may look different than the page you were viewing on the web.
Please recycle it when you're done reading.

The URI for this page is { http://cc.byexamples.com }

fprintf to print text on standard output screen, why? Posted on January 24th

We can actually do this to print text on screen,

fprintf(stdout,"Hello %s\n","World");

But why?

Try to imagine that you are doing a debug log file function, which to print “debug string” to a file with specified FILE such as this

So when you want to write the debug string to file, pass the “file output stream”, print on screen? pass “stdout”.

FILE is a stream object, when you create a stream pointer, you can point to stdout. stdout is a standard output defined when you initiate main(). You can do something fun, look at another example bellow

The code above redirect the standard output to a file “out-snap” and I uses fp to preserved the stdout address. Later I do fclose(stdout), I was actually closing the file stream and point back the stdout to standard output.

Trackback URL
Leave your own comments about this post: