Problem description:
There is a string that may contain English letters (uppercase and lowercase), numbers, and special characters. Now you need to implement a function to select the vowels in the string and store them in another string, and sort the letters in the string from small to large (the lower-case vowels are in the front, and the upper-case vowels are in the back order ).
Note:
1. the vowels are A, E, I, O, U, A, E, I, O, U.
2. The selected vowels do not need to be removed.
The final output string. The lower-case vowels are listed at the top, and the upper-case vowels are listed at the back.
Required implementation functions:
Void sort_vowel (char * input, char * output );
Input: char * input, indicating the input string
Output: char * output, sorted vowel string
The C code is as follows:
#include<stdio.h>#include<stdlib.h>#include<ctype.h>#include<string.h>int cmp(const void* a, const void* b);int is_vowel(char a);void sort_vowel(char* input, char* output);int main(){char input[1000] = {'\0'};char output[200] = {'\0'};printf("please input the original str: ");gets(input);printf("the sorted vowel is: ");sort_vowel(input,output);return 0;}int cmp(const void* a, const void* b){return *(char*)a - *(char*)b;}int is_vowel(char a){if(a=='a' || a=='e' || a=='i' || a=='o' || a=='u' ||a=='A' || a=='E' || a=='I' || a=='O' || a=='U')return 1;elsereturn 0;}void sort_vowel(char* input, char* output){char low[100] = {'\0'};char up[100] ={'\0'};int low_index=0;int up_index=0;while(*input != '\0'){if(is_vowel(*input)){if(isupper(*input)){up[up_index++] = *input;input++;continue;}else{low[low_index++] = *input;input++;continue;}}input++;}qsort(up,strlen(up),sizeof(char),cmp);qsort(low,strlen(low),sizeof(char),cmp);strcat(low,up);strcpy(output,low);while(*output != '\0')printf("%c",*output++);printf("\n");}
Several groups of test cases are as follows: