#include<stdio.h>
typedef struct{
char buf[10];
char ptr;
}A;
main()
{
char *s = "adcABC+-/*123";
char *p,tmp;
A upper,normal,num,other;
int i,len;
memset(&upper,0,sizeof(A));
memset(&normal,0,sizeof(A));
memset(&num,0,sizeof(A));
memset(&other,0,sizeof(A));
len = strlen(s); //获取源字符串长度
p = s;
for (i=0; i<len; i++)
{
tmp = p[i];
if ((tmp>='A') && (tmp<='Z')) //大写字母
upper.buf[upper.ptr++] = tmp;
else if ((tmp>='a') && (tmp<='z')) //小写字母
normal.buf[normal.ptr++] = tmp;
else if ((tmp>='0') && (tmp<='9')) //数字
num.buf[num.ptr++] = tmp;
else //其它字符
other.buf[other.ptr++] = tmp;
}
printf("%s",upper.buf);
printf("%s",normal.buf);
printf("%s",num.buf);
printf("%s",other.buf);
getchar();
}
温馨提示:答案为网友推荐,仅供参考