Determines the orientation of a stream.
#include <stdio.h> int fwide(FILE *stream, int orientation);
stream
A pointer to a stream.
orientation
The desired orientation.
The fwide() function determines the orientation of the stream pointed to by stream. If the value of orientation is greater than zero and stream has no orientation, stream is made to be wide-oriented. If the value of orientation is less than zero and stream has no orientation, stream is made to be byte-oriented. Otherwise, if value of orientation is zero then the function does not alter the orientation of the stream. In all cases, if stream already has an orientation, it will not be changed.
The fwide() function returns a value greater than zero if, after the call, the stream has wide orientation, a value less than zero if the stream has byte orientation, or zero if the stream has no orientation.
#include <stdio.h> int main() { FILE * fp; char filename[FILENAME_MAX]; int orientation; char * cptr; cptr = tmpnam(filename); fp = fopen(filename, "w"); orientation = fwide(fp, 0); // A newly opened file has no orientation printf("Initial orientation = %i\n", orientation); fprintf(fp, "abcdefghijklmnopqrstuvwxyz\n"); // A byte oriented output operation will set the orientation // to byte oriented orientation = fwide(fp, 0); printf("Orientation after fprintf = %i\n", orientation); fclose(fp); fp = fopen(filename, "r"); orientation = fwide(fp, 0); printf("Orientation after reopening = %i\n", orientation); orientation = fwide(fp, -1); // fwide with a non-zero orientation argument will set an // unoriented file's orientation printf("Orientation after fwide = %i\n", orientation); orientation = fwide(fp, 1); // but will not change the file's orientation if it // already has an orientation printf("Orientation after second fwide = %i\n",orientation); fclose(fp); remove(filename); return 0; } Output: Initial orientation = 0 Orientation after fprintf = -1 Orientation after reopening = 0 Orientation after fwide = -1 Orientation after second fwide = -1