输出:char* output,排好序之后的元音字符串
C代码如下:
#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; else return 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"); }
将一个字符串的元音字母复制到另一个字符串,并排序,布布扣,bubuko.com
原文地址:http://blog.csdn.net/hs794502825/article/details/38047911