Compartir a través de


Input and Output (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Routines by Category

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.

Routine Use
clearerr Clears error indicator for stream
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
fprintf, fwprintf Writes formatted data to stream
fputc, fputwc Writes a character to a stream
fputs, fputws Writes string to stream
fread Reads unformatted data from stream
fscanf, fwscanf Reads formatted data from stream
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
printf, wprintf Writes formatted data to stdout
putchar, putwchar Writes character to stdout
puts, _putws Writes line to stream
scanf, wscanf Reads formatted data from stdin
_snprintf Writes formatted data of specified length to string
sprintf, swprintf Writes formatted data to string
sscanf, swscanf Reads formatted data from string
ungetc, ungetwc Pushes character back onto stream
vfprintf, vfwprintf Writes formatted data to stream
vprintf, vwprintf Writes formatted data to stdout
_vsnprintf, _vsnwprintf Writes formatted data of specified length to buffer
vsprintf, vswprintf Writes formatted data to buffer
_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 or _fdopen.

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

Microsoft C Run-time Library for Windows CE | Run-time Library Reference

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.