Format
#include <stdio.h>
#include <wchar.h>
int fwide(FILE *stream, int mode);
Language Level: ANSI
Threadsafe: Yes.
Locale Sensitive: This function is not available when LOCALETYPE(*CLD) is specified on the compilation command.
Integrated File System Interface: This function is not available when SYSIFCOPT(*NOIFSIO) is specified on the compilation command.
Description
The fwide() function determines the orientation of the stream pointed to by stream. If mode is greater than 0, the fwide() function first attempts to make the stream wide oriented. If mode is less than 0, the fwide() function first attempts to make the stream byte oriented. Otherwise, mode is 0, and the fwide() function does not alter the orientation of the stream.
Return Value
If, after the call, the stream has wide orientation, the fwide() function returns a value greater than 0. If the stream has byte orientation, it returns a value less than 0. If the stream has no orientation, it returns 0.
Example that uses fwide()
#include <stdio.h>
#include <math.h>
#include <wchar.h>
void check_orientation(FILE *stream)
{
int rc;
rc = fwide(stream,0); /* check the orientation */
if (rc<0) {
printf("Stream has byte orientation.\n");
} else if (rc>0) {
printf("Stream has wide orientation.\n");
} else {
printf("Stream has no orientation.\n");
}
return;
}
int main(void)
{
FILE *stream;
/* Demonstrate that fwide can be used to set the orientation,
but cannot change it once it has been set. */
stream = fopen("test.dat","w");
printf("After opening the file: ");
check_orientation(stream);
fwide(stream, -1); /* Make the stream byte oriented */
printf("After fwide(stream, -1): ");
check_orientation(stream);
fwide(stream, 1); /* Try to make the stream wide oriented */
printf("After fwide(stream, 1): ");
check_orientation(stream);
fclose(stream);
printf("Close the stream\n");
/* Check that a wide character output operation sets the orientation
as expected. */
stream = fopen("test.dat","w");
printf("After opening the file: ");
check_orientation(stream);
fwprintf(stream, L"pi = %.5f\n", 4* atan(1.0));
printf("After fwprintf( ): ");
check_orientation(stream);
fclose(stream);
return 0;
/*******************************************************************
The output should be similar to :
After opening the file: Stream has no orientation.
After fwide(stream, -1): Stream has byte orientation.
After fwide(stream, 1): Stream has byte orientation.
Close the stream
After opening the file: Stream has no orientation.
After fwprintf( ): Stream has wide orientation.
*******************************************************************/
}
Related Information