Thread: sorting vocals

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    1

    Question 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.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    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
    My best code is written with the delete key.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    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
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  2. Sorting Algorithm Help
    By cjwenigma in forum C++ Programming
    Replies: 8
    Last Post: 11-02-2007, 02:04 PM
  3. sorting structure members using pointers
    By robstr12 in forum C Programming
    Replies: 5
    Last Post: 07-25-2005, 05:50 PM
  4. Sorting words with a fast, effincient sorting method
    By Unregistered in forum C++ Programming
    Replies: 19
    Last Post: 07-12-2002, 04:21 PM
  5. Still Needing Help : selection sorting
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 10-14-2001, 08:41 PM