题目描述:有一字符串,里面可能包含英文字母(大写、小写)、数字、特殊字符,现在需要实现一函数,将此字符串中的元音字母挑选出来,存入另一个字符串中,并对字符串中的字母进行从小到大的排序(小写的元音字母在前,大写的元音字母在后,依次有序)。
说明:
1、 元音字母是a,e,i,o,u,A,E,I,O,U。
2、 筛选出来的元音字母,不需要剔重;
3. 最终输出的字符串,小写元音字母排在前面,大写元音字母排在后面,依次有序。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <memory.h>
void sortVowel(char *ch,char *b)
{
int n,j,len,i;
//char *tmp=b;
char temp1[20]="\0";
char temp2[20]="\0";
char p;
n=strlen(ch);
i=0;j=0;
while (*ch!='\0')
{
if(*ch == 'a'||*ch == 'e'||*ch == 'i'||*ch == 'u'||*ch == 'o')
{
temp1[i]=*ch;
i++;
}
else if(*ch == 'A'||*ch == 'E'||*ch == 'I'||*ch == 'O'||*ch == 'U')
{
temp2[j]=*ch;
j++;
}
ch++;
}
for (i=0;i<(strlen(temp1)-1);i++)
{
for (j=i+1;j<=strlen(temp1)-1;j++)
{
if (temp1[i]>temp1[j])
{
p=temp1[i];
temp1[i]=temp1[j];
temp1[j]=p;
}
}
*b=temp1[i];
b++;
}
for (i=0;i<(strlen(temp2)-1);i++)
{
for (j=i+1;j<=strlen(temp2)-1;j++)
{
if (temp2[i]>temp2[j])
{
p=temp2[i];
temp2[i]=temp2[j];
temp2[j]=p;
}
}
*b=temp2[i];
b++;
}
}
void main()
{
char *stringin=(char *)malloc (sizeof(char)*50);
char stringout[50]="\0";//空字符串初始化时必须赋初值
printf("请输入字符串:\n");
scanf("%s",stringin);
sortVowel(stringin,stringout);
printf("%s",stringout);
}