blob: 801cecc204dbfd3c285c1e439c3d4d47f43db857 [file]
<html lang="en">
<head>
<title>ungetc - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Stdio.html#Stdio" title="Stdio">
<link rel="prev" href="tmpnam.html#tmpnam" title="tmpnam">
<link rel="next" href="ungetwc.html#ungetwc" title="ungetwc">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="ungetc"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="ungetwc.html#ungetwc">ungetwc</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="tmpnam.html#tmpnam">tmpnam</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Stdio.html#Stdio">Stdio</a>
<hr>
</div>
<h3 class="section">4.66 <code>ungetc</code>&mdash;push data back into a stream</h3>
<p><a name="index-ungetc-321"></a><a name="index-g_t_005fungetc_005fr-322"></a><strong>Synopsis</strong>
<pre class="example"> #include &lt;stdio.h&gt;
int ungetc(int <var>c</var>, FILE *<var>stream</var>);
int _ungetc_r(struct _reent *<var>reent</var>, int <var>c</var>, FILE *<var>stream</var>);
</pre>
<p><strong>Description</strong><br>
<code>ungetc</code> is used to return bytes back to <var>stream</var> to be read again.
If <var>c</var> is EOF, the stream is unchanged. Otherwise, the unsigned
char <var>c</var> is put back on the stream, and subsequent reads will see
the bytes pushed back in reverse order. Pushed byes are lost if the
stream is repositioned, such as by <code>fseek</code>, <code>fsetpos</code>, or
<code>rewind</code>.
<p>The underlying file is not changed, but it is possible to push back
something different than what was originally read. Ungetting a
character will clear the end-of-stream marker, and decrement the file
position indicator. Pushing back beyond the beginning of a file gives
unspecified behavior.
<p>The alternate function <code>_ungetc_r</code> is a reentrant version. The
extra argument <var>reent</var> is a pointer to a reentrancy structure.
<p><br>
<strong>Returns</strong><br>
The character pushed back, or <code>EOF</code> on error.
<p><br>
<strong>Portability</strong><br>
ANSI C requires <code>ungetc</code>, but only requires a pushback buffer of one
byte; although this implementation can handle multiple bytes, not all
can. Pushing back a signed char is a common application bug.
<p>Supporting OS subroutines required: <code>sbrk</code>.
<p><br>
</body></html>