C语言中文网php,fwide - [ C语言中文开发手册 ] - 在线原生手册 - php中文网

在头文件中定义int fwide(FILE * stream,int mode);(自C95以来)

如果mode > 0,试图使stream广泛导向。如果mode < 0,试图使stream字节为导向。如果mode==0仅查询流的当前方向。

如果流的方向已经确定(通过执行输出或通过先前调用fwide),则此函数不执行任何操作。

参数

流-指向要修改或查询的CI / O流的指针模式-大于零的整数值将流设置为宽度,小于零以将流设置为窄,或者仅将零设置为仅查询

返回值

如果流在此调用后面向全局,则为大于零的整数,如果流在此调用后面向字节,则小于零;如果流没有定向,则为零。

以下代码设置并重置流的方向。

#include #include #include void try_read(FILE* fp){

int c = fgetc(fp);    if(c == EOF) puts("narrow character read failed");    else printf("narrow character read '%c'\n", c);

wint_t wc = fgetwc(fp);    if(wc == WEOF) puts("wide character read failed");    else printf("wide character read '%lc'\n", wc);}void show(int n){    if(n == 0) puts("no orientation");    else if (n 

FILE* fp = fopen("main.cpp","r");    if (!fp) {        perror("fopen() failed");        return EXIT_FAILURE;    }

// A newly opened stream has no orientation.    show(fwide(fp, 0));

// Establish byte orientation.    show(fwide(fp, -1));    try_read(fp);

// Only freopen() can reset stream orientation.    if (freopen("main.cpp","r",fp) == NULL)    {       perror("freopen() failed");       return EXIT_FAILURE;    }

// A reopened stream has no orientation.    show(fwide(fp, 0));

// Establish wide orientation.    show(fwide(fp, 1));    try_read(fp);

fclose(fp);}

可能的输出:

no orientation

narrow orientation

narrow character read '#'wide character read failed

no orientation

wide orientation

narrow character read failed

wide character read '#'

参考

C11标准(ISO / IEC 9899:2011):7.29.3.5 fwide函数(p:423)

C99标准(ISO / IEC 9899:1999):7.24.3.5 fwide函数(p:369)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值