fwide ()- 确定流方向
格式
#include <stdio.h>
#include <wchar.h>
int fwide(FILE *stream, int mode);语言级别
ANSI
线程安全
是
语言环境敏感
当在编译命令上指定 LOCALETYPE (*CLD) 时,此功能不可用。
集成文件系统界面
当在编译命令上指定 SYSIFCOPT (*NOIFSIO) 时,此功能不可用。
描述
fwide() 函数确定 stream指向的流的方向。 如果 方式 大于 0 ,那么 fwide() 函数会首先尝试使流面向范围。 如果 方式 小于 0 ,那么 fwide() 函数将首先尝试使流面向字节。 否则, mode 为 0 ,并且 fwide() 函数不会改变流的方向。
注: 如果已确定流的方向,那么
fwide() 函数不会对其进行更改。返回值
如果在调用后流具有宽方向,那么 fwide() 函数将返回大于 0 的值。 如果流具有字节方向,那么它将返回小于 0 的值。 如果流没有方向,那么它将返回 0。
示例
#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.
*******************************************************************/
}