Thread: Sorting help for newbie

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    4

    Red face Sorting help for newbie

    I am very new to programming. I am trying to use STL sorting (#include<algorithm>) to sort an array alphabetically, but it is not working.
    Here's my code:

    Code:
    char num[]="F A C B D E G";
    sort(num,num+7);
    for (int i=0;i<7;i++)
    cout<<num[i]<<" ";
    What am I doing wrong???
    Last edited by raymarquise; 08-11-2006 at 07:45 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    There are thirteen characters in your array (not counting the null). Remove the spaces between the characters.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    4
    Thanks, that worked!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting algorithms, worst-case input
    By Leftos in forum C++ Programming
    Replies: 17
    Last Post: 06-15-2009, 01:33 PM
  2. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  3. sorting structure members using pointers
    By robstr12 in forum C Programming
    Replies: 5
    Last Post: 07-25-2005, 05:50 PM
  4. Still Needing Help : selection sorting
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 10-14-2001, 08:41 PM
  5. selection sorting
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 10-13-2001, 08:05 PM