Thread: Alphabetical Sort

  1. #1

    Question Alphabetical Sort

    I read in a list of commands from a file into a two dimensional array. I now need to sort these commands in alphabetical order. I was wondering if anyone knows where I can get a alphabetical sorting algorithm for C. If anyone can point me in the right direction it would be great.



  2. #2
    Search this board for recent examples of the use of qsort (which is a standard function in stdlib.h)

  3. #3
    Registered User
    Join Date
    Sep 2001
    How about writing your own? Wouldn't THAT be a novel idea?
    You could try a simple bubble sort on the array by testing the first character of each element.


    char array[4][4];
    char *tmp;
    int i;
    for(i = 0; i < 4; i++) {
      if(array[i][0] > array[i + 1][0]) {
        tmp = array[i];
        array[i] = array[i + 1];
        array[i + 1] = tmp;
    (This code probably doesn't work, it's just an example.
    You should be able to figure it out from this.)
    The box said 'Windows NT or better', so I installed Linux.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Straight Insertion Sort function problem
    By StaticKyle in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2008, 04:03 AM
  2. threaded merge sort
    By AusTex in forum Linux Programming
    Replies: 4
    Last Post: 05-04-2005, 04:03 AM
  3. Replies: 2
    Last Post: 02-07-2003, 12:09 PM
  4. Shell Sort vs Heap Sort vs Quick Sort
    By mackol in forum C Programming
    Replies: 6
    Last Post: 11-22-2002, 08:05 PM
  5. Alphabetical sort using STRCMP()
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 03-27-2002, 07:44 PM