C语言代码 判断输入的字符是不是字母

判断输入的字符是不是字母

代码示例:

#include 
int main()
{
	char ch = 0;
	while (scanf("%c", &ch) == 1)
	{
		if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
		{
			printf("%c is an alphabet.\n", ch);
		}
		else
		{
			printf("%c is not an alphabet.\n", ch);
		}
		getchar( );//用于处理输入字符末尾的\n
	}
	return 0;
}

运行结果:

5
5 is not an alphabet.
D
D is an alphabet.
a
a is an alphabet.
*
* is not an alphabet.

分析:

        getchar( );用于处理输入字符末尾的\n

你可能感兴趣的:(算法,c语言,开发语言)