满意答案
guojie7
2018.06.29
采纳率:57% 等级:13
已帮助:13663人
/*
将一个字符串中的字母,数字字符分离出来,分别放入两个数组之中
*/
#include
void main()
{
char *p,s[80],zm[80];
int sz[80];
int alpha,space,digit,other;
int i;
alpha=space=digit=other=0;
printf("input string: ");
gets(s);
for(p=s;*p!='\0';p++)
if( (*p>='a'&&*p<='z') || (*p>='A'&&*p<='Z') )
else if(*p==32) space++; //空格的ASCII码为32
else if(*p>='0' &&*p<='9' )
else other++;
printf("alpha:%d space:%d digit:%d other:%d\n",alpha,space,digit,other);
printf("字符数组内容为:");
for(i=0;i
{
printf("%c ",zm[i]);
}
printf("\n");
printf("数字数组内容为:");
for(i=0;i
{
printf("%d ",sz[i]);
}
printf("\n");
}
01分享举报