把一个字符退回到输入流中
int ungetc(char c, FILE *stream);
c 要写入的字符,stream 文件流指针
字符c - 操作成功,EOF - 操作失败
#include <stdio.h>
#include <ctype.h>
void main( void )
{
int ch;
int result = 0;
printf( "Enter an integer: " );
/* Read in and convert number: */
while( ((ch = getchar()) != EOF) && isdigit( ch ) )
result = result * 10 + ch - '0'; /* Use digit. */
if( ch != EOF )
ungetc( ch, stdin ); /* Put nondigit back. */
printf( "Number = %d\Nextcharacter in stream = '%c'",
result, getchar() );
}
Enter an integer: 521a
Number = 521Nextcharacter in stream = 'a'