Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Parse a Sentence
Index -> Programming, C -> C Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rar




PostPosted: 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
Sponsor
sponsor
Insectoid




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: