-
sorting vocals
I had a problem,my teacher asked me to do a C++ program that asks the user to input his name,then the program must sort the vocals of the name,for example:
your name: louis
output: i
o
u
but I only know how to sort numbers,and If anybody can help me
i would appreciate it.
Sorry for my english.
-
Simply loop through the array and test for isVowel(). If the function returns 0 then it is and you can print it, otherwise just continue looping to the next element.
Code:
int isVowel ( char ch )
{
ch = toupper ( ch );
if ( ch == 'A' || ch == 'E' ||
ch == 'I' || ch == 'O' ||
ch == 'U' )
return 0;
return 1;
}
-Prelude
-
Sorry, misread your question. You can sort individual characters just like numbers, but when you have more than one character to test such as "ae" then you will need to use strcpy.
Code:
if ( a[i] == a[j] )
swap ( a[i], a[j] );
-Prelude