# Alphabetical Sorting String Array HELP

Page 1 of 1

## 2 Replies - 15717 Views - Last Post: 27 January 2009 - 05:37 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=83134&amp;s=9eb8a571837b06d49f1c648f6f651500&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Nike_Unltd

Reputation: 0
• Posts: 14
• Joined: 13-August 08

# Alphabetical Sorting String Array HELP

Posted 27 January 2009 - 01:52 PM

Hello Dream in code experts =],

I have an string array of 10 elements called wordList which has this:
```yamaha, jack, harry, zena, google, peter, bob, ken, dude, pokemon

```

as you can see they are not not in alphabetical order. my question is, how can i sort these!?

Is This A Good Question/Topic? 0

## Replies To: Alphabetical Sorting String Array HELP

### #2 Gloin

• Expert Schmexpert...

Reputation: 235
• Posts: 4,489
• Joined: 04-August 08

## Re: Alphabetical Sorting String Array HELP

Posted 27 January 2009 - 02:01 PM

First you should decide on some sorting algorithm that you want to use. A simple sorting algorithm is Bubblesort. You can find an implementation of it in the snippets section or through wikipedia.

To compare two strings you can use the function strcmp, it takes 2 strings as parameters and uses a comparator method to decide which string is smaller/larger. You can find an explanation of the function here.. http://www.cplusplus...ing/strcmp.html

[rules][/rules]

### #3 buckrogers1965

• New Member

Reputation: 9
• Posts: 87
• Joined: 23-January 09

## Re: Alphabetical Sorting String Array HELP

Posted 27 January 2009 - 05:37 PM

There is a qsort() and bsearch() built into C. bsearch() only works on sorted data.

There is an example with strings.
http://www.engin.umd...400/c/sort.html

Here is one of my examples with ints:
http://linuxgazette....rs_example05c.c

About halfway down I have a brief explanation of a qsort() and bsearch():
http://linuxgazette....e39/rogers.html

I also discuss return values. The examples should help you learn hot to create the comparator function for your data.

This post has been edited by buckrogers1965: 27 January 2009 - 05:38 PM