提取字符串中的元音字母并排序

题目描述:有一字符串,里面可能包含英文字母(大写、小写)、数字、特殊字符,现在需要实现一函数,将此字符串中的元音字母挑选出来,存入另一个字符串中,并对字符串中的字母进行从小到大的排序(小写的元音字母在前,大写的元音字母在后,依次有序)。

说明:

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);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值