#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 = %dnNextcharacter in stream = '%c'",
result, getchar() );
}
Output
Enter an integer: 521a Number = 521 Nextcharacter in stream = 'a'
最后
以上就是谦让冰淇淋最近收集整理的关于利用getc 和ungetc的实例的全部内容,更多相关利用getc内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复