2.3 Wide-Character Versus Byte I/O Functions

The wide-character I/O functions provide operations analogous to most of the byte I/O functions, except that the fundamental units internal to the wide-character functions are wide characters.

However, the external representation (in files) is a sequence of multibyte characters, not wide characters. For the wide-character formatted input and output functions:

Byte I/O functions cannot handle state-dependent encodings. Wide- character I/O functions can. They accomplish this by associating each wide-character stream with a conversion-state object of type mbstate_t.

The wide-character I/O functions are:

fgetwc        fputwc        fwscanf       fwprintf       ungetwc
fgetws        fputws        wscanf        wprintf
getwc         putwc                       vfwprintf
getwchar      putwchar                    vwprintf

The byte I/O functions are:

fgetc         fputc         fscanf        fprintf         ungetc
fgets         fputs         scanf         printf          fread
getc          putc                        vfprinf         fwrite
gets          puts                        vprintf
getchar       putchar

The wide-character input functions read multibyte characters from the stream and convert them to wide characters as if they were read by successive calls to the fgetwc function. Each conversion occurs as a call were made to the mbrtowc function with the conversion state described by the stream's own mbstate_t object.

The wide-character output functions convert wide characters to multibyte characters and write them to the stream as if they were written by successive calls to the fputwc function. Each conversion occurs as if a call were made to the wcrtomb function, with the conversion state described by the I/O stream's own mbstate_t object.

If a wide-character I/O function encounters an invalid multibyte character, the function sets errno to the value EILSEQ.


Previous Page | Next Page | Table of Contents | Index