编写程序C语言 从键盘输入一个字符,判断是字母,数字,还是其它字符

2024-11-20 09:23:18
推荐回答(4个)
回答1:

用ASCII码判断就行,一个字符对应一个整型数,或调用库函数ctype

回答2:

#include "stdio.h"
void main()
{
char temp;
temp=getch();
if(temp>='a'&&temp<='z')
printf("xiao xie zi mu");
else if(temp>='A'&&temp<='Z')
printf("da xie zi mu");
if(temp>='0'&&temp<='9')
printf("shuzi");
else printf("other zi mu");
}

回答3:

#include "stdio.h"
#include "bios.h"
#include "ctype.h"
main(){
int key;
key=bioskey(0);
if(isalnum(key&0xff)){
if(((char)key>='a'&&(char)key<='z')||((char)key>='A'&&(char)key<='Z'))
printf("you input a char.\n");
else
printf("you input a number.\n");
}
else
printf("you input a teshu zifu.");

getch();
}

回答4:

#include
main()
{char c;
c=getchar()
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
printf("it is ");
else if(c>='0'&&c<='9')
printf("it is a number");
else printf("it is others");}