⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib_file.html

📁 ST20 Embedded Toolset R2.0.5用于开发基于ST20芯片机顶盒软件的开发平台,2.0.5版本,国内找不到的.在国外论坛上花了N天才找到!
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<H2><A NAME="Controlling Streams">Controlling Streams</A></H2><P><A HREF="stdio.html#fopen"><CODE>fopen</CODE></A>returns the address of an object of type<A HREF="stdio.html#FILE"><CODE>FILE</CODE></A>.You use this address as the <CODE>stream</CODE> argument to several libraryfunctions to perform various operations on an open file. For a bytestream, all input takes place as if each character is read by calling<A HREF="stdio.html#fgetc"><CODE>fgetc</CODE></A>,and all output takes place as if each character is written by calling<A HREF="stdio.html#fputc"><CODE>fputc</CODE></A>.For a wide stream (with<A HREF="lib_over.html#Amendment 1">Amendment 1</A>),all input takes place as if each character is read by calling<A HREF="wchar.html#fgetwc"><CODE>fgetwc</CODE></A>,and all output takes place as if each character is written by calling<A HREF="wchar.html#fputwc"><CODE>fputwc</CODE></A>.</P><P>You can<B><A NAME="file close">close</A></B> a file by calling<A HREF="stdio.html#fclose"><CODE>fclose</CODE></A>,after which the address of the<A HREF="stdio.html#FILE"><CODE>FILE</CODE></A> object is invalid.</P><P>A <A HREF="stdio.html#FILE"><CODE>FILE</CODE></A>object stores the state of a stream, including:</P><UL><LI>an <B><A NAME="error indicator">error indicator</A></B> --set nonzero by a function that encounters a read or write error</LI><LI>an <B><A NAME="end-of-file indicator">end-of-file indicator</A></B> --set nonzero by a function thatencounters the end of the file while reading</LI><LI>a <B><A NAME="file-position indicator">file-position indicator</A></B> --specifies the next byte in the stream to read or write,if the file can support positioning requests</LI><LI>a <A HREF="#Stream States">stream state</A> --specifies whether the stream will accept reads and/or writes and, with<A HREF="lib_over.html#Amendment 1">Amendment 1</A>, whether the stream is<A HREF="#unbound stream">unbound</A>,<A HREF="#byte oriented">byte oriented</A>, or<A HREF="#wide oriented">wide oriented</A></LI><LI>a <A HREF="charset.html#conversion state">conversion state</A> --remembers the state of any partly assembled or generated<A HREF="#generalized multibyte characters">generalized multibyte character</A>, as well asany shift state for the sequence of bytes in the file)</LI><LI>a <B><A NAME="file buffer">file buffer</A></B> --specifies the address and size of an array objectthat library functions can use to improve the performanceof read and write operations to the stream</LI></UL><P>Do not alter any value stored in a<A HREF="stdio.html#FILE"><CODE>FILE</CODE></A> object or ina file buffer that you specify for use with that object.You cannot copy a<A HREF="stdio.html#FILE"><CODE>FILE</CODE></A> objectand portably use the address of the copyas a <CODE>stream</CODE> argument to a library function.</P><H2><A NAME="Stream States">Stream States</A></H2><P>The valid states, and state transitions, for a stream areshown in the diagram.</P><P><IMG SRC="stream.gif"></P><P>Each of the circles denotes a stablestate. Each of the lines denotes a transition that can occur as theresult of a function call that operates on the stream. Five groupsof functions can cause state transitions.</P><P>Functions in the first three groups are declared in<A HREF="stdio.html"><CODE>&lt;stdio.h&gt;</CODE></A>:</P><UL><LI>the <B><A NAME="byte read functions">byte read functions</A></B> --<A HREF="stdio.html#fgetc"><CODE>fgetc</CODE></A>,<A HREF="stdio.html#fgets"><CODE>fgets</CODE></A>,<A HREF="stdio.html#fread"><CODE>fread</CODE></A>,<A HREF="stdio.html#fscanf"><CODE>fscanf</CODE></A>,<A HREF="stdio.html#getc"><CODE>getc</CODE></A>,<A HREF="stdio.html#getchar"><CODE>getchar</CODE></A>,<A HREF="stdio.html#gets"><CODE>gets</CODE></A>,<A HREF="stdio.html#scanf"><CODE>scanf</CODE></A>,and<A HREF="stdio.html#ungetc"><CODE>ungetc</CODE></A></LI><LI>the <B><A NAME="byte write functions">byte write functions</A></B> --<A HREF="stdio.html#fprintf"><CODE>fprintf</CODE></A>,<A HREF="stdio.html#fputc"><CODE>fputc</CODE></A>,<A HREF="stdio.html#fputs"><CODE>fputs</CODE></A>,<A HREF="stdio.html#fwrite"><CODE>fwrite</CODE></A>,<A HREF="stdio.html#printf"><CODE>printf</CODE></A>,<A HREF="stdio.html#putc"><CODE>putc</CODE></A>,<A HREF="stdio.html#putchar"><CODE>putchar</CODE></A>,<A HREF="stdio.html#puts"><CODE>puts</CODE></A>,<A HREF="stdio.html#vfprintf"><CODE>vfprintf</CODE></A>, and<A HREF="stdio.html#vprintf"><CODE>vprintf</CODE></A></LI><LI>the <B><A NAME="position functions">position functions</A></B> --<A HREF="stdio.html#fflush"><CODE>fflush</CODE></A>,<A HREF="stdio.html#fseek"><CODE>fseek</CODE></A>,<A HREF="stdio.html#fsetpos"><CODE>fsetpos</CODE></A>, and<A HREF="stdio.html#rewind"><CODE>rewind</CODE></A></LI></UL><P>Functions in the remaining two groups are declaredin <CODE>&lt;wchar.h&gt;</CODE>:</P><UL><LI>the <B><A NAME="wide read functions">wide read functions</A></B> --<A HREF="wchar.html#fgetwc"><CODE>fgetwc</CODE></A>,<A HREF="wchar.html#fgetws"><CODE>fgetws</CODE></A>,<A HREF="wchar.html#fwscanf"><CODE>fwscanf</CODE></A>,<A HREF="wchar.html#getwc"><CODE>getwc</CODE></A>,<A HREF="wchar.html#getwchar"><CODE>getwchar</CODE></A>,<A HREF="wchar.html#ungetwc"><CODE>ungetwc</CODE></A>,and<A HREF="wchar.html#wscanf"><CODE>wscanf</CODE></A></LI><LI>the <B><A NAME="wide write functions">wide write functions</A></B> --<A HREF="wchar.html#fwprintf"><CODE>fwprintf</CODE></A>,<A HREF="wchar.html#fputwc"><CODE>fputwc</CODE></A>,<A HREF="wchar.html#fputws"><CODE>fputws</CODE></A>,<A HREF="wchar.html#putwc"><CODE>putwc</CODE></A>,<A HREF="wchar.html#putwchar"><CODE>putwchar</CODE></A>,<A HREF="wchar.html#vfwprintf"><CODE>vfwprintf</CODE></A>,<A HREF="wchar.html#vwprintf"><CODE>vwprintf</CODE></A>, and<A HREF="wchar.html#wprintf"><CODE>wprintf</CODE></A>,</LI></UL><P>For the stream <CODE>s</CODE>, the call<CODE><A HREF="wchar.html#fwide">fwide</A>(s, 0)</CODE>is always valid and never causes a change of state. Any other call to<A HREF="wchar.html#fwide"><CODE>fwide</CODE></A>, or to any of the fivegroups of functions described above, causes the state transition shownin the state diagram. If no such transition is shown, the functioncall is invalid.</P><P>The state diagram shows how to establish the orientation ofa stream:</P><UL><LI>The call<CODE><A HREF="wchar.html#fwide">fwide</A>(s, -1)</CODE>,or to a byte read or byte write function, establishes the stream as<A HREF="#byte oriented">byte oriented</A>.</LI><LI>The call<CODE><A HREF="wchar.html#fwide">fwide</A>(s, 1)</CODE>,or to a wide read or wide write function, establishes the stream as<A HREF="#wide oriented">wide oriented</A>.</LI></UL><P>The state diagram shows that you must call one of the positionfunctions between most write and read operations:</P><UL><LI>You cannot call a read function if the last operation on thestream was a write.</LI><LI>You cannot call a write function if the last operation on thestream was a read, unless that read operation set the<A HREF="#end-of-file indicator">end-of-file indicator</A>.</LI></UL><P>Finally, the state diagram shows that a position operation never<I>decreases</I> the number of valid function calls that can follow.</P><HR><P>See also the<B><A HREF="index.html#Table of Contents">Table of Contents</A></B> and the<B><A HREF="_index.html">Index</A></B>.</P><P><I><A HREF="crit_pb.html">Copyright</A> &#169; 1989-2002by P.J. Plauger and Jim Brodie. All rights reserved.</I></P><!--V4.01:1125--></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -