主函数初始化字符串,设计子函数进行拆解分类。主要为英文写,英文小写,数字,和,其他符号。
怎么拆呢?存哪里?是要分成四个字符串吗?
#include <stdio.h>
#include <stdlib.h>
//主函数初始化字符串,设计子函数进行拆解分类。主要为英文写,英文小写,数字,和,其他符号
void fun(char *src,char *upper,char *lower,char *number,char *other)
{
int i=0,j=0,k=0,m=0,n=0;
while(src[i] != '\0')
{
if(src[i] >='A' && src[i] <='Z')
upper[j++] = src[i];
else if(src[i] >='a' && src[i] <='z')
lower[k++] = src[i];
else if(src[i] >='0' && src[i] <='9')
number[m++] = src[i];
else
other[n++] = src[i];
i++;
}
}
int main(void) {
char src[1000],upper[1000]={0},lower[1000] = {0},number[1000] = {0},other[1000] = {0};
gets(src);
fun(src,upper,lower,number,other);
printf("大写字符有:%s\n",upper);
printf("小写字符有:%s\n",lower);
printf("数字字符有:%s\n",number);
printf("其它字符有:%s\n",other);
return 0;
}