Syntax: fprintf(stdout, <string format>, <arguments>);
Example: fprintf(stdout, "Print using fprintf");
C Runtime maintains an array of FILE structures named _iob[] (VC++ compiler) for accessing file system APIs. For example: if we want to open a file:
FILE * fp = NULL;
fp = fopen(<file path>, <mode>);
C runtime returns a pointer from this array. Now, at the application start up time, C Runtime creates/opens three file pointers named stdin, stdout and stderr. They are the first three points of the array elements. The definition is given below:
#define stdin  (&_iob[0])
#define stdout (&_iob[1])
#define stderr (&_iob[2])
Stdin is the FILE pointer to access console input which is, by default, the keyboard in PC. Stdout and stderr are the FILE pointer to access console output which is, by default, VGA/SVGA console in PC. Stdout is used for normal output printing whereas stderr is used for error outputs.

C runtime never accesses the keyboard or display consoles directly. Instead it sends the string buffer to the file and from the device driver output goes to the corresponding devices. This mechanism is very useful when dealing with different types of input and output devices. In embedded systems, serial ports are often used as input and output devices. Printf/Scanf never opens the file directly. We have to set the default console to serial port from kernel or using set console handle option. Stdin, Stdout and stderr will be changed accordingly.

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

scan string with blanks, scanf string ends with newline, return of scanf, return of printf, scanf with printf, print using fprintf, take input using fscanf, floating point formatting, pointers,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan