# Sorting of numbers or strings.

Discussion in 'C Programming' started by Mars, Mar 2, 2005.

1. ### MarsGuest

I don't know whether the inputs are all numbers or all strings...
if they are numbers, they are sorted as numbers,
if they are strings, they are sorted as strings....

e.g.

input : 9 12 2 4
output : 2 4 9 12

input : orange Banana
ouput : Banana orange

How can I do so??

Mars, Mar 2, 2005

2. ### CBFalconerGuest

Mars wrote:
>
> I don't know whether the inputs are all numbers or all strings...
> if they are numbers, they are sorted as numbers,
> if they are strings, they are sorted as strings....
>
> e.g.
>
> input : 9 12 2 4
> output : 2 4 9 12
>
> input : orange Banana
> ouput : Banana orange
>
> How can I do so??

What are you going to do with:

input : 9 orange 12 2 banana 4

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the

CBFalconer, Mar 2, 2005

3. ### Walter RobersonGuest

In article <4225e691\$-cable.com>, Mars <Mars@Mars> wrote:
:I don't know whether the inputs are all numbers or all strings...
:if they are numbers, they are sorted as numbers,
:if they are strings, they are sorted as strings....

Deciding whether they are all numeric? Sorting?
--
Those were borogoves and the momerathsoutgrabe completely mimsy.

Walter Roberson, Mar 2, 2005
4. ### Eric SosmanGuest

Mars wrote:
> I don't know whether the inputs are all numbers or all strings...
> if they are numbers, they are sorted as numbers,
> if they are strings, they are sorted as strings....
>
>
> e.g.
>
> input : 9 12 2 4
> output : 2 4 9 12
>
> input : orange Banana
> ouput : Banana orange

You might find

http://sourcefrog.net/projects/natsort/

helpful. (Yes, that's "frog," not "forge.") Last
time I looked, the C implementation had several
occurrences of the "pass a plain `char' to a <ctype.h>
function" error, but those are easily repaired.

--

Eric Sosman, Mar 2, 2005