功 能
把一個字元退回到輸入流中用 法
int ungetc(char c, FILE *stream);輸入參數
c 要寫入的字元,stream 檔案流指針輸出參數
字元c - 操作成功,EOF - 操作失敗程式例
#include#include
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\nNextcharacter in stream = '%c'",
result, getchar() );
}
Output
Enter an integer: 521a
Number = 521Nextcharacter in stream = 'a'