比如
if(c>='0' &&c<档笑逗='9') printf("%c 是数字\n",c)
else printf("%c 不是数字升州\n",c)
如果判断要经常使用,可以将该功能封装为函数:
int is_num(char c)
{
return (c>='0' &&c<='9')
}
或者宏定义:
#define is_num(c) (c>='0' &&c<='9')
可以使用代码进行判断:乱拍神
#include<stdio.h>
intmain()
{
charc
while(scanf("%c",&c)!=EOF)
{
getchar()
if(c>='0'&&c<='9')
printf("%c是数字\n",c)
elseif(c>='a'&&c<='z'||c>='A'&&c<='Z')
printf("%c是字母\n",c)
elseprintf("%c是特殊字符\n",c)
}
return0
}
扩展资料
C语言判断输入是否是数贺答字
intdigit
printf("pleaseinputainteger\n")
intret=scanf("%d"哗亏,&digit)
if(0==ret)
{
printf("youshouldinputainteger\n")
system("pause")
return0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)