473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Sort the words in a sentence.

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
Nov 17 '05 #1
3 1537
"Tracey" <Tr****@discussions.microsoft.com> wrote in message
news:04**********************************@microsof t.com...
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
Nov 17 '05 #2
Thanks. It's not a homework. I just want to do more coding exercises using
raw C.
"William DePalo [MVP VC++]" wrote:
"Tracey" <Tr****@discussions.microsoft.com> wrote in message
news:04**********************************@microsof t.com...
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

Nov 17 '05 #3
"Tracey" <Tr****@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.com...
Thanks. It's not a homework. I just want to do more coding exercises using
raw C.


Then take a look at this:

http://msdn.microsoft.com/library/de..._crt_qsort.asp

Regards,
Will
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kamilche | last post by:
I've written a generic sort routine that will sort dictionaries, lists, or tuples, either by a specified key or by value. Comments welcome! import types def sort(container, key = None,...
7
by: HumanJHawkins | last post by:
Hi all, I have a table of text and associated data. I want to break apart the text into individual words, yet retain the data in other columns. For example: Sentence: Chapter:...
7
by: Nomak | last post by:
Hello, i have a bug i can't find. I hope somebody will have some ideas... Here is the bad peace of code: int compare_sentence(sentence * s1, sentence * s2) { assert(s1);
0
by: PLENI SELENE | last post by:
HOW TECHNOLOGY MOVES FROM TALK TO ELECTRONIC DEVICES TO SPEAK GOOD SPANISH! Would you Like To Know How The Electronic Devices Understand When You Talk to Them, And How It Works To...
6
by: gk245 | last post by:
Basically, i want to make a function that will receive a sentence or phrase, and count its words. It would start like this (i think): #include <stdio.h> int count ( char sentence ) {...
6
by: mike | last post by:
Hello, I am trying to write some code to parse a sentence and hyperlink just the words in it. I used Aaron's code from an earlier question as a start. So far, all the code does below is...
19
by: fellya | last post by:
Hi, i don't have enough experience in writing codes in Python but now i'm trying to see how i can start using Python. I've tried to write a simple program that can display a sentence. now my...
1
by: fellya | last post by:
Hi, i don't have enough experience in writing codes in Python but now i'm trying to see how i can start using Python. I've tried to write a simple program that can display a sentence. now my...
2
by: dechen | last post by:
How do I compare words of sentences with a dictionary and get it's corresponding value. e.g, This is the dictionary format. WORD Pronunciation try t-r-y-0| ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.