ungetc(3C)
_________________________________________________________________
ungetc function
Return a character to the input buffer.
_________________________________________________________________
Calling Sequence
#include <stdio.h>
FILE *fp;
char next;
ungetc(next, fp);
where next is a character placed in the look-ahead byte of
the buffer to which fp points.
Description
Use the ungetc function to return a character to the input buffer
that you specify with fp. You must specify fp. You lose any
character already in the look-ahead buffer.
See the "Input/Output Functions and Macros" section of Chapter 1
for information on buffering with I/O functions and macros.
Returns
The ungetc function returns the character pushed (next).
Related Functions
See also the fgetc function and the getc and getchar macros.
Example
/* Program test for the ungetc() function */
#include <stdio.h>
char digit;
main(argc, argv)
int argc;
char *argv[];
{
while ((digit = getchar()) != EOF) {
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
ungetc(3C)
if (('0' <= digit) && (digit <= '9'))
putchar(digit);
else {
ungetc(digit, *stdin);
exit();
}
}
}
If you call the program test and enter
1776AD
the program will print the digits 1776 and then place the first
nondigit A back into the standard input buffer.
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)