Input and Output (Windows Embedded CE 6.0)
1/5/2010
Input and output functions process data in different sizes and formats, from single characters to large data structures.
These functions also provide buffering, which can improve performance. The default size of a stream buffer is 4K.
Input and output functions affect buffers created by the run-time library routines and have no effect on buffers created by the OS.
For detailed reference information about the CRT functions, see Alphabetical Function Reference (CRT).
Routine | Use |
---|---|
clearerr |
Clears error indicator for stream |
clearerr_s |
Security-enhanced version of clearerr. |
fclose, _fcloseall |
Closes stream |
feof |
Tests for end of file on stream |
ferror |
Tests for error on stream |
fflush |
Flushes stream to buffer or storage device |
fgetc, fgetwc |
Reads character from stream |
fgetpos |
Gets position indicator of stream |
fgets, fgetws |
Reads string from stream |
_fileno |
Gets file handle associated with stream |
_flushall |
Flushes all streams to buffer or storage device |
fopen, _wfopen |
Opens stream. These functions have been deprecated because security-enhanced versions, fopen_s and _wfopen_s, now exist. |
fopen_s¸ _wfopen_s |
Opens a file. Security-enhanced versions of deprecated functions fopen and _wfopen. Denies read/write sharing by default. |
fprintf, fwprintf |
Writes formatted data to stream. These functions have been deprecated because security-enhanced versions, fprintf_s and fworintf_s, now exist. |
fprintf_s, fwprintf_s |
Prints formatted data to a stream. Security-enhanced versions of deprecated functions fprintf and fwprintf. Windows Embedded CE 6.0 does not support forms of this function that accept a Locale parameter, _fprint_s_l and fwprint_s_l. |
fputc, fputwc |
Writes a character to a stream |
fputs, fputws |
Writes string to stream |
fread |
Reads unformatted data from stream. Invokes the invalid parameter handler. |
fscanf, fwscanf |
Reads formatted data from stream. These functions have been deprecated because security-enhanced versions, fscanf_s and _fwscanf_s, now exist. |
fscanf_s, _fwscanf_s |
Reads formatted data from a stream. Security-enhanced versions of deprecated functions fscanf and fwscanf. Requires buffer length. Windows Embedded CE 6.0 does not support forms of this function that accept a Locale parameter,_fscanf_s_l and fwscanf_s_l. |
fseek |
Moves file position to given location |
fsetpos |
Sets position indicator of stream |
ftell |
Gets current file position |
fwrite |
Writes unformatted data items to stream |
getchar, getwchar |
Reads character from stdin |
gets, _getws |
Reads line from stdin. These functions have been deprecated because security-enhanced versions, gets_s and _getws_s, now exist. |
gets_s, _getws_s |
Gets a line from the stdin stream. Security-enhanced version of deprecated functions gets and _getws. Template overload available. |
printf, wprintf |
Writes formatted data to stdout. These functions have been deprecated because security-enhanced versions, printf_s and wprintf_s, now exist. |
printf_s, wprintf_s |
Prints formatted output to the standard output stream. Security-enhanced versions of printf and wprintf. Windows Embedded CE 6.0 does not support forms of this function that use the Locale parameter printf_s_l, and wprintf_s_l. |
putchar, putwchar |
Writes character to stdout |
puts, _putws |
Writes line to stream |
scanf, wscanf |
Reads formatted data from stdin. These functions have been deprecated because security-enhanced versions, scanf_s and wscanf_s, now exist. |
scanf_s, wscanf_s |
Reads formatted data from the standard input stream. Security-enhanced versions of deprecated functions scanf and wscanf. Requires buffer size. Windows Embedded CE 6.0 does not support forms of this function that use the Locale parameter, scanf_s_l, and wscanf _s_l. |
_snprintf |
Writes formatted data of specified length to string. This functions hasbeen deprecated because security-enhanced versions, _snprintf_s and _snwprintf_s, now exist. |
_snprintf_s, _snwprintf_s |
Writes formatted data to a string. Security-enhanced versions of deprecated functions _snprintf and _snwprintf. Validates parameters, returns errors. Template overload available. Windows Embedded CE 6.0 does not support forms of this function that use the Locale parameter, snprintf_s_l, and snwprintf_s_l. |
sprintf, swprintf |
Writes formatted data to string. These functions have been deprecated because security-enhanced versions, sprint_s and swprintf_s, now exist. |
sprintf_s, swprintf_s |
Writes formatted data to a string. Security-enhanced versions of deprecated functions sprintf and swprintf. Windows Embedded CE 6.0 does not support forms of this function that use the Locale parameter, sprintf_s_l, and swprintf_s_l. |
sscanf, swscanf |
Reads formatted data from string. These functions have been deprecated because security-enhanced versions, sscanf_s and swscanf_s, now exist. |
sscanf_s, swscanf_s |
Reads formatted data from a string. Security-enhanced versions of sscanf and swscanf. Requires buffer size. Windows Embedded CE 6.0 does not support forms of this function that use the Locale parameter, sscanf_s_l, swscanf_s_l. |
ungetc, ungetwc |
Pushes character back onto stream |
vfprintf, vfwprintf |
Writes formatted data to stream. These functions have been deprecated because security-enhanced versions, _vfprintf_s, and _vfwprintf_s now exist. |
_vfprintf_s, _vfwprintf_s |
Writes formatted output using a pointer to a list of arguments. Security-enhanced versions of vfprintf and vfwprintf. Windows Embedded CE 6.0 does not support forms of this function that use the Locale parameter _vfprintf_s_l and vfwprintf_s_l. |
vprintf, vwprintf |
Writes formatted data to stdout. These functions have been deprecated because security-enhanced versions, vprintf_s, and vwprintf_s, now exist. |
vprintf_s, vwprintf_s |
Writes formatted output using a pointer to a list of arguments. Security-enhanced versions of deprecated functions vprintf and vwprintf. Windows Embedded CE 6.0 does not support forms of this function that use the Locale parameter _vprintf_s_l and vwprintf_s_l. |
_vsnprintf, _vsnwprintf |
Writes formatted data of specified length to buffer. These functions have been deprecated because security-enhanced versions, _vsnprintf_s, and _vsnwprintf_s, now exist. |
_vsnprintf_s, _vsnwprintf_s |
Writes formatted output using a pointer to a list of arguments. Security-enhanced versions of deprecated functions vsnprintf and _vsnwprintf. Windows Embedded CE 6.0 does not support forms of this function that use the Locale parameter _vsnprintf_s_l and vsnwprintf_s_l. |
vsprintf, vswprintf |
Writes formatted data to buffer. These functions have been deprecated because security-enhanced versions, vsprintf_s, and vswprintf_s, now exist. |
vsprintf_s, vswprintf_s |
Writes formatted output using a pointer to a list of arguments. Security-enhanced versions of deprecated functions vsprintf and vswprintf. Validates parameters and sets errno. Template overload available. Windows Embedded CE 6.0 does not support forms of this function that use the Locale parameter _vsprintf_s_l and vswprintf_s_l. |
_wfdopen |
Associates a stream with a file opened for low-level IO |
_wfreopen |
Reassigns a file pointer |
When a program begins execution, the startup code automatically opens several streams: standard input (pointed to by stdin), standard output (pointed to by stdout), and standard error (pointed to by stderr). These streams are directed to the console (keyboard and screen) by default.
Files opened using the stream routines are buffered by default. The stdout and stderr functions are flushed whenever they are full or, if you are writing to a character device, after each library call.
If a program terminates abnormally, output buffers may not be flushed, resulting in loss of data. Use fflush or _flushall to ensure that the buffer associated with a specified file or all open buffers are flushed to the operating system, which can cache data before writing it to disk.
The commit-to-disk feature ensures that the flushed buffer contents are not lost in the event of a system failure.
There are two ways to commit buffer contents to disk:
- Link with the file COMMODE.OBJ to set a global commit flag. The default setting of the global flag is n, for no-commit.
- Set the mode flag to c with fopen_s or _fdopen_s.
Any file specifically opened with either the c or the n flag behaves according to the flag, regardless of the state of the global commit/no-commit flag.
If your program does not explicitly close a stream, the stream is automatically closed when the program terminates. However, you should close a stream when your program finishes with it, as the number of streams that can be open at one time is limited.
Input can follow output directly only with an intervening call to fflush or to a file-positioning function (fseek, fsetpos, or rewind). Output can follow input without an intervening call to a file-positioning function if the input operation encounters the end of the file.
See Also
Concepts
Other Resources
C/C++ Libraries for Windows Embedded CE
What's New in the C Run-Time Library