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
 
Thanks. It's not a homework. I just want to do more coding exercises using
raw C.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top