题目 1033: [编程入门]自定义函数之字符提取

问题描述:

写一函数,将一个字符串中的元音字母复制到另一个字符串,然后输出。

样例输入:

abcde                

样例输出:

ae

问题分析:

我们定义了一个名为 copyVowels 的函数。这个函数接受两个参数:input 是指向输入字符串的指针,output 是指向存放元音字母的字符串的指针。函数通过遍历输入字符串,如果遇到元音字母('a', 'e', 'i', 'o', 'u'),就将其复制到输出字符串中,最后在输出字符串的末尾添加一个空字符 \0 以表示字符串结束。

代码实现:

#include <stdio.h>

void copyVowels(const char *input, char *output) {
    while (*input != '\0') {
        char c = *input;
        if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
            *output = c;
            output++;
        }
        input++;
    }
    *output = '\0'; // 在目标字符串末尾添加空字符,以表示字符串的结束
}

int main() {
    char input[100];
    char output[100];
    scanf("%s", input); // 使用scanf读取输入的字符串

    copyVowels(input, output);

    printf("%s", output);

    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值