1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
<h1 id="firstHeading" class="firstHeading">fwide</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><wchar.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl"> <td> <pre data-language="c">int fwide( FILE *stream, int mode );</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c95">(since C95)</span> </td> </tr> </table> <p>If <code>mode > 0</code>, attempts to make <code>stream</code> wide-oriented. If <code>mode < 0</code>, attempts to make <code>stream</code> byte-oriented. If <code>mode==0</code>, only queries the current orientation of the stream.</p>
<p>If the orientation of the stream has already been decided (by executing output or by an earlier call to fwide), this function does nothing.</p>
<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> stream </td> <td> - </td> <td> pointer to the C I/O stream to modify or query </td>
</tr> <tr class="t-par"> <td> mode </td> <td> - </td> <td> integer value greater than zero to set the stream wide, less than zero to set the stream narrow, or zero to query only </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> <p>An integer greater than zero if the stream is wide-oriented after this call, less than zero if the stream is byte-oriented after this call, and zero if the stream has no orientation.</p>
<h3 id="Example"> Example</h3> <div class="t-example">
<p>The following code sets and resets the stream orientation.</p>
<div class="c source-c"><pre data-language="c">#include <wchar.h>
#include <stdio.h>
#include <stdlib.h>
void show_orientation(int n)
{
n < 0 ? puts("\tnarrow orientation"):
n > 0 ? puts("\twide orientation"):
puts("\tno orientation");
}
void try_read(FILE* fp)
{
int c = fgetc(fp);
if(c == EOF)
puts("\tnarrow character read failed");
else
printf("\tnarrow character read '%c'\n", c);
wint_t wc = fgetwc(fp);
if(wc == WEOF)
puts("\twide character read failed");
else
printf("\twide character read '%lc'\n", wc);
}
int main(void)
{
enum fwide_orientation { narrow = -1, query, wide };
FILE* fp = fopen("main.cpp", "r");
if (!fp)
{
perror("fopen() failed");
return EXIT_FAILURE;
}
puts("1) A newly opened stream has no orientation.");
show_orientation(fwide(fp, query));
puts("2) Establish byte orientation.");
show_orientation(fwide(fp, narrow));
try_read(fp);
puts("3) Only freopen() can reset stream orientation.");
if (freopen("main.cpp", "r", fp) == NULL)
{
perror("freopen() failed");
return EXIT_FAILURE;
}
puts("4) A reopened stream has no orientation.");
show_orientation(fwide(fp, query));
puts("5) Establish wide orientation.");
show_orientation(fwide(fp, wide));
try_read(fp);
fclose(fp);
}</pre></div> <p>Possible output:</p>
<div class="text source-text"><pre data-language="c">1) A newly opened stream has no orientation.
no orientation
2) Establish byte orientation.
narrow orientation
narrow character read '#'
wide character read failed
3) Only freopen() can reset stream orientation.
4) A reopened stream has no orientation.
no orientation
5) Establish wide orientation.
wide orientation
narrow character read failed
wide character read '#'</pre></div> </div> <h3 id="References"> References</h3> <ul>
<li> C17 standard (ISO/IEC 9899:2018): </li>
<ul><li> 7.29.3.5 The fwide function (p: 309) </li></ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.29.3.5 The fwide function (p: 423) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.24.3.5 The fwide function (p: 369) </li></ul>
</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="fopen" title="c/io/fopen"> <span class="t-lines"><span>fopen</span><span>fopen_s</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> opens a file <br> <span class="t-mark">(function)</span> </td>
</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/io/c/fwide" title="cpp/io/c/fwide">C++ documentation</a></span> for <code>fwide</code> </td>
</tr> </table> <div class="_attribution">
<p class="_attribution-p">
© cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
<a href="https://en.cppreference.com/w/c/io/fwide" class="_attribution-link">https://en.cppreference.com/w/c/io/fwide</a>
</p>
</div>
|