Sort the words in a sentence.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to write a function to sort the words in a sentence. Suppose there
is only one space between words.
For example, the input string is "They are Jonny and Jone". And ideal result
is
"and are Jone Jonny They".

I know that I can get it done using existing functions. I'm thinking to
solve the problem in C language nicely. Any suggestion would be aprreciated!

Thx
 
Tracey said:
I'm trying to write a function to sort the words in a sentence. Suppose
there
is only one space between words.
For example, the input string is "They are Jonny and Jone". And ideal
result
is
"and are Jone Jonny They".

I know that I can get it done using existing functions. I'm thinking to
solve the problem in C language nicely. Any suggestion would be
aprreciated!

Homework?

In C, strtok() can be used to decompose a string into tokens. qsort() sorts
arrays of things given a comparator. In fact, the help entry for one of
those functions has an example along the lines of what you seek.

Regards,
Will
 
Back
Top