char_int.c

来自「《c与指针》书的代码 是我学习这本书时候敲出来的」· C语言 代码 · 共 31 行

C
31
字号
/*
** Convert a series of digits from the standard input to an integer.
*/

#include <stdio.h>
#include <ctype.h>

int
read_int()
{
	int	value;
	int	ch;

	value = 0;

	/*
	** Convert digits from the standard input; stop when we get a
	** character that is not a digit.
	*/
	while( ( ch = getchar() ) != EOF && isdigit( ch ) ){
		value *= 10;
		value += ch - '0';
	}

	/*
	** Push back the nondigit so we don't lose it.
	*/
	ungetc( ch, stdin );
	return value;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?