Parse a Sentence
Author |
Message |
rar
|
Posted: Thu Feb 11, 2010 4:27 pm Post subject: Parse a Sentence |
|
|
I have a new assignment that requires me to parse a sentence. I am to read in a sentence, divide it into words, and sort those words alphabetically.
How would I go about parsing a string? Am I to look for characters like , . ? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Thu Feb 11, 2010 4:30 pm Post subject: RE:Parse a Sentence |
|
|
I suggest you look for a space, then once you've found one, take that word (assuming it's the first), drop any leading/trailing special characters and poof, there's your word. Then look for the next space, and so on. |
|
|
|
|
|
DtY
|
Posted: Thu Feb 11, 2010 6:51 pm Post subject: Re: RE:Parse a Sentence |
|
|
insectoid @ Thu Feb 11, 2010 4:30 pm wrote: I suggest you look for a space, then once you've found one, take that word (assuming it's the first), drop any leading/trailing special characters and poof, there's your word. Then look for the next space, and so on. This is called tokenizing, and there's a standard C function to do it; http://www.cplusplus.com/reference/clibrary/cstring/strtok/ |
|
|
|
|
|
rar
|
Posted: Tue Feb 23, 2010 3:25 pm Post subject: RE:Parse a Sentence |
|
|
Hmm alright...I think I may make use of the strtok function, but I might be able to figure it out otherwise....
I'm more confused about the second part, where we have to sort it alphabetically...will the string compare function work for this? |
|
|
|
|
|
Insectoid
|
Posted: Tue Feb 23, 2010 3:50 pm Post subject: RE:Parse a Sentence |
|
|
I'm sure C has something like that. Perl and ruby have it, at least. |
|
|
|
|
|
rar
|
Posted: Tue Feb 23, 2010 4:57 pm Post subject: RE:Parse a Sentence |
|
|
turns out I should not use strtok, so I'm going to tokenize the string without that function. |
|
|
|
|
|
|
|