河道疏浚外观质量标准:求C程序,要求测试输入的一个字符是数字,字母,空白还是其它

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/09 14:55:08
求C程序,要求测试输入的一个字符是数字,字母,空白还是其它
我写了一下,不是很尽人意,求高数指点,最好具体给出程序

#include<stdio.h>
main()
{
char a;
printf("please input a");
a=getchar();
if(a>='0'&&a<='9')
printf("you has inputed a number");
else if(a>='a'&&a<='z'||a>='A'&&a<='Z')
printf("you has inputed a letter");
else if(a==' ') /*注意' '里面有一个空格*/
printf("you has inputed a letter");
else
printf("orthers");
getchar();
getchar();
}

本来很想帮你的,可是我已经两年没看C了,要是不着急的话,晚上回去给你问问,明天给答案,呵呵:)

char x;
x=getchar();

if(x>'0'&&x<'9')printf("Numeri");
else if(x>'A'&&x<'Z'||x>'a'&&x<'z')printf("DSKFJlkdsj");
if(x==' ')printf("jsdkfjslkdfja;lskdf");

#include<stdio.h>
main()
{
char a;
a=getchar();
if(a>='0'&&a<='9')
printf("shuzi");
else if(a>='a'&&a<='z'||a>='A'&&a<='Z')
printf("zimu");
else if(a==' ')
printf("kongbai");
else
printf("qita");
getch();
}

#include <stdio.h>
#include <ctype.h>
main()
{
char c;
c=getchar();
{
if (isdigit(c)) printf("It's a number.\n"); //数字
if (isalpha(c)) printf("It's a letter.\n"); //字母
if (isspace(c)) printf("It's a space.\n"); //空格
if (ispunct(c)) printf("It's other char.\n"); //其它
}
}
全部用库函数可以完成。ctype.h