Syntax: fscanf(stdin, <string format>, <arguments>); Example: fprintf(stdin, "%s", buffer);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 pointers to access console output which is, by default, VGA/SVGA console (display device) 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 reads the string buffer from the file and the device driver returns the buffer from 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.
About our authors: Team EQA
You have viewed 1 page out of 252. Your C learning is 0.00% complete. Login to check your learning progress.