Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/u/ungetc.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/u/ungetc.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/u/ungetc.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/u/ungetc.html on line 8
Push a character back onto an input stream
#include <stdio.h>
int ungetc( int c,
FILE *fp );
- c
- The character that you want to push back.
- fp
- The stream you want to push the character back on.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The ungetc() function pushes the character specified by
c back onto the input stream pointed to by fp.
This character will be returned the next time that you read from the stream.
The pushed-back character is discarded if you call
fflush()
or a file-positioning function
(fseek(),
fsetpos(),
or
rewind())
before performing the next read operation.
Only one character (the most recent one) of pushback is guaranteed.
The ungetc() function clears the end-of-file indicator, unless the
value of c is EOF.
The character pushed back.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main( void )
{
FILE *fp;
int c;
long value;
fp = fopen( "file", "r" );
value = 0;
c = fgetc( fp );
while( isdigit(c) ) {
value = value*10 + c - '0';
c = fgetc( fp );
}
ungetc( c, fp ); /* put last character back */
printf( "Value=%ld\n", value );
fclose( fp );
return EXIT_SUCCESS;
}
ANSI,
POSIX 1003.1
Safety: | |
Cancellation point |
Yes |
Interrupt handler |
No |
Signal handler |
No |
Thread |
Yes |
fopen(),
getc(),
getc_unlocked(),
ungetwc()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/u/ungetc.html on line 158
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/u/ungetc.html on line 158