
-----------------------------------
rar
Thu Feb 11, 2010 4:27 pm

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 , .   ?

-----------------------------------
Insectoid
Thu Feb 11, 2010 4:30 pm

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
Thu Feb 11, 2010 6:51 pm

Re: 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.This is called tokenizing, and there's a standard C function to do it; http://www.cplusplus.com/reference/clibrary/cstring/strtok/

-----------------------------------
rar
Tue Feb 23, 2010 3:25 pm

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
Tue Feb 23, 2010 3:50 pm

RE:Parse a Sentence
-----------------------------------
I'm sure C has something like that. Perl and ruby have it, at least.

-----------------------------------
rar
Tue Feb 23, 2010 4:57 pm

RE:Parse a Sentence
-----------------------------------
turns out I should not use strtok, so I'm going to tokenize the string without that function.
