解题思路:
注意事项:
参考代码:
/*****************************************************
*Copyright (C) UnionMems Co., Ltd. 2018. Allrights reserved
* File name: copy_vowels.c
* Author: Wanghg
* Version: 1.0
* Date: 2018/11/15
* Description: Copy the vowels in a string to another string.
*****************************************************/
#include<stdio.h>
#define ORIGIN_SIZE 100
#define VOWEL_SIZE 50
void copy_vowels(char*,char*); /*function declaration*/
int main(void)
{
char oringin_str[ORIGIN_SIZE] = {0}; /*initialize the string array*/
char vowels_str[VOWEL_SIZE] = {0};
gets(oringin_str); /*Enter the original string*/
copy_vowels(oringin_str,vowels_str); /*calling the copy_vowels function*/
puts(vowels_str); /*Output all elements of the vowel string */
return 0;
}
/*****************************************************
* Function: copy_vowels
* Description: Copy the vowels in a string to another string
* Input(s): *oringin_str,*vowels_str
* output(s): NO
* Return: NO
* Author: wanghg
* History: NO
*****************************************************/
void copy_vowels(char *oringin_str,char *vowels_str)
{
int length = 0;
while(*oringin_str != '\0')
{
if((*oringin_str == 'a') || (*oringin_str == 'e') || (*oringin_str == 'o') ||
(*oringin_str == 'i') || (*oringin_str == 'u')) /*Is it vowel?*/
{
vowels_str[length] = *oringin_str; /*Put vowels into the string vowels_str*/
length++;
}
oringin_str++;
}
vowels_str[length + 1] = '\0';
}
0.0分
0 人评分