summaryrefslogtreecommitdiff
path: root/devdocs/c/io%2Ffwide.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/c/io%2Ffwide.html')
-rw-r--r--devdocs/c/io%2Ffwide.html97
1 files changed, 97 insertions, 0 deletions
diff --git a/devdocs/c/io%2Ffwide.html b/devdocs/c/io%2Ffwide.html
new file mode 100644
index 00000000..4918f246
--- /dev/null
+++ b/devdocs/c/io%2Ffwide.html
@@ -0,0 +1,97 @@
+ <h1 id="firstHeading" class="firstHeading">fwide</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;wchar.h&gt;</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 &gt; 0</code>, attempts to make <code>stream</code> wide-oriented. If <code>mode &lt; 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 &lt;wchar.h&gt;
+#include &lt;stdio.h&gt;
+#include &lt;stdlib.h&gt;
+
+void show_orientation(int n)
+{
+ n &lt; 0 ? puts("\tnarrow orientation"):
+ n &gt; 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">
+ &copy; 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>