# Thread: Sorting a set of numbers.... I should remember this....

1. ## Sorting a set of numbers.... I should remember this....

Hi

Sorry for such a trivial question (this has to come up in the first semester of any comp-sci course), but I need to sort a string of numbers, no longer than 32 digits each, in "dictionary order".

So

11111111
112
131
4
52343
53

like in a dictionary you have a, with aa before ab, then b, c, d etc.

Thanks!

2. but what exactly do you want to do with the strings after they're in order? place them in a vector?

3. If you have strings and you want to compare them/sort them, as strings, then you'll want to use strcmp(string1, string2), where the returned value will indicate which is greater. (Positive 1 means right side is greater, negative 1 means left side is greater than right.)

Code:
```int comp;
comp = strcmp(string1, string2);```

4. Originally Posted by Adak
(Positive 1 means right side is greater, negative 1 means left side is greater than right.)
Strictly speaking 1 and -1 are not necessarily the values that will be returned; the C standard only requires some positive and some negative integer respectively.

Popular pages Recent additions