参考代码如下:
#include <stdio.h> #include <string.h> #include <stdlib.h> char *find_vowels(char *str) { int len = strlen(str); char *vowels = (char*)malloc(len + 1); //最多只有len个元音,故开辟这么长空间 int i; int j = 0; for (i = 0; i < len; i++) { if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u') { vowels[j++] = str[i]; } } vowels[j] = '\0'; //添加结束符到最后一位 return vowels; } int main() { char str[100]; scanf("%s", str); char *output = NULL; output = find_vowels(str); printf("%s\n", output); return 0; }
0.0分
0 人评分