6-27 实验9_7_设计函数int getVowel(char str[],char vowel[])

设计函数int getVowel(char str[],char vowel[]),将只包含小写字母的字符串str中的元音字母“a”“e”“i”“o”“u”复制到字符数组vowel,并返回字符串vowel的长度。

函数接口定义:

 

函数原型如下: int getVowel(char str[],char vowel[]);

其中 str 和 vowel 都是用户传入的参数。 str 为原始字符串; vowel 为元音字母字符串。函数的返回值为 vowel 的长度。

裁判测试程序样例:

 

函数被调用进行测试的例子如下:
#include <stdio.h>
#include<stdio.h>

//将只包含小写字母的字符串str中的元音字母复制到字符数组vowel,并返回元音字符的个数。
int getVowel(char str[],char vowel[]);
 
int main()
{
    char    vowel[101] , str[101];//每个数组都至少要101个字节 
    int        len ;
    
    scanf("%s",str);    //读入字符串 
    len = getVowel(str,vowel);    //复制 
    if ( len > 0 ) printf("%d %s\n", len , vowel);    //输出复制后结果 
    else printf("%d\n", len);//仅输出长度 
    
    return 0;    
}

/* 请在这里填写答案 */

输入样例:

abcdefghiijklmn

输出样例:

4 aeii

注意要在vowel字符数组后面加'\0'; 

int getVowel(char str[],char vowel[])
{
    int count=0;
    for(int i=0;str[i]!='\0';i++)
    {
        if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u')
        {
            vowel[count++]=str[i];
        }
    }
    vowel[count]='\0';
    return count;
}

 

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值