//方法一:
int main()
{
printf("please input one character:\n");
input=getchar();
while(input==10) //如果输入的是回车键,则再次输入;因为回车键也是一个字符;
{
printf("please input again:\n");
input=getchar();
}
if(input <= 32)
printf("You have input a control character!!\n");
else if(input >= 48 && input <= 57) //数字;
{
for( i=48;i<58;i++)
{
if(input==i)
break;
}
printf("You put a number,ranging from 0--9!\n The number is %d!\n ",i);
}
else if(input >=65 && input <=90 ) //大写字母;
{
for( i=65; i<=90; i++)
{
if(input==i)
break;
}
printf("You have put a uppercase! Ranging from A--Z!\nThe number is %d!\n",i);
}
else if(input >=97 && input <=122) //小写字母
{
for( i=97;i<=122;i++)
{
if(i==input)
break;
}
printf("You have input a lowercase! Ranging from a--z!\nThe number is %d\n",i);
}
else
printf("You have input a other character!\n");
}
方法二:用isalnum()函数来判断输入的字符是否是数字还是字符;
char * character="JFKSKS%%$$#$(()(^!!!kjhefwew!!!";
printf("The date are:JFKSKS%%$$#$(()(^!!!kjhefwew!!!");
printf("The date are:\n");
char *strs=malloc(sizeof(character));
strcpy(strs,character);
for(i=0;strs[i]!=0;i++)
if(isalnum(strs[i]))
printf("%c is a character!!\n",strs[i]);