循环读取每一个字符,再进行条件判断,分为大写英文字母、小写字母、数字、其他字符,分别输出upper letter、lower letter、digit、other character。把源程序复制一下
#include
#include
#include
int main()
{
char ch[100];
int i;
int length;
printf("please input a string:\n");
scanf("%s",ch);
length=strlen(ch);
printf("the length is %d\n",length);
for(i=0;i{
if(ch[i]<='Z' && ch[i]>='A')
{
printf("the %d character is upper letter\n",i+1);
}
else
{
if(ch[i]<='z' && ch[i]>='a')
{
printf("the %d character is lower letter\n",i+1);
}
else
{
if(ch[i]<='9' && ch[i]>='0')
{
printf("the %d character is digit\n",i+1);
}
else
{
printf("the %d character is other character\n",i+1);
}
}
}
}
return 0;
}
运行结果,如果有什么不明白的还可以问我