In C, fwide() checks or sets a stream's byte or wide orientation. It belongs to the wide-character tools declared in <wchar.h>.
Use wchar_t for wide characters and prefix wide literals with L, as in L"Hello". The examples below use simple C Programming Tutorial patterns and print wide strings with %ls.
Syntax
The following concrete call shows the argument shape before the formal declaration.
C
fwide(fp, 1);
Call
What it does
fwide(fp, 1)
Checks or sets a stream's byte or wide orientation in a typical call.
Include <wchar.h>. Add only the supporting headers actually used by your program.
Library declaration
int fwide(FILE *stream, int mode);
Parameters
Parameter
Description
stream
The FILE stream to read, write, inspect, or push back into.
mode
Positive requests wide orientation, negative requests byte orientation, and zero only queries.
Return Value
Return Value
Description
Positive
The stream is wide-oriented.
Zero
The stream is still unoriented.
Negative
The stream is byte-oriented. This is not an I/O failure.
C Examples
Example 1 — Request wide orientation
This example uses fwide() to request wide orientation, then exposes the result so you can connect the call with its output.
Prepare a practical variation. The data is arranged specifically to orient before i/o.
Use the stream correctly.fwide(fp, 1) performs the wide-oriented stream operation.
Notice the safety rule. The example keeps the count, destination capacity, stream state, and terminator requirements visible.
Interpret the output.wide request = yes confirms the behavior demonstrated by this example.
Frequently Asked Questions
fwide() checks or sets a stream's byte or wide orientation. It is part of the standard wide-character library.
Its parameters are stream, mode. stream: The FILE stream to read, write, inspect, or push back into. mode: Positive requests wide orientation, negative requests byte orientation, and zero only queries.
Positive means the stream is wide-oriented. Zero means the stream is still unoriented. Negative means the stream is byte-oriented. This is not an I/O failure.
Include <wchar.h> for fwide(). Include only the supporting headers used by your program, such as <stdio.h> for FILE or <stdarg.h> for va_list.
Do not mix byte I/O and wide I/O after a stream becomes oriented. Check WEOF or the documented status before using data.