例如:
输入:Thdad29#@12aH;77
输出:
ThdadaH
291277
#@;
#include <stdio.h>
#include <string.h>
int main(){
char a[100];
char cha[100]={'\0'};
char other[100]={'\0'};
char num[100]={'\0'};
int ncha=0,not=0,nnum=0;
gets(a);
int n=strlen(a);
for(int i=0;i<n;i++)
{
if(a[i]>='A'&&a[i]<='Z'||a[i]>='a'&&a[i]<='z')
{ cha[ncha]=a[i];
ncha++;
}
else if(a[i]>='0'&&a[i]<='9')
{ num[nnum]=a[i];
nnum++;
}
else { other[not]=a[i];
not++;
}
}
puts(cha);
puts(num);
puts(other);
}
运行结果:

C代码示例展示了如何使用gets函数获取输入,然后依据ASCII码范围对字符进行分类,输出字母、数字和特殊字符部分。

被折叠的 条评论
为什么被折叠?



