I wrote a simple object called words_list which takes a string and splits it into words. Its main use would probably be parsing, since for example it'll take something like this:
It leaves line comments (since it works line-by-line, multi-line comments can't be supported) and whitespace out of the words it produces, and strings inside quotation marks are all one word.
strtok = String Tokenize, basically it breaks down a string into the component pieces i.e. words. It pretty much does what your trying to do with your code. That said, I think your code is great, it gives you the basis to make much more complex stuff that is (and I think this is important sometimes) completely independent of outside calls.
For general-purpose use your whitespace should probably include tab characters. Strtok is fast and easy to use, but a byte scanner is probably a better choice where you need the length of each token and/or where you need to detect errors such as unmatched quotes.
Actually, it's mostly a learning thing. Like I said, the code's pretty much a hack, but it might be useful and that's why I wrote it. I don't really care if there's something else that already does that, as using that other tool won't really teach me anything. Sure, it's good to use other tools, but there's nothing wrong with writing your own thing, is there?
P.S. This is an object. I could write an object based on strtok() but in any case it doesn't matter... my point is that using an object makes it a much more natural interface.
Sure, it's good to use other tools, but there's nothing wrong with writing your own thing, is there?
No, there's nothing wrong with it. Especially when your learning to program I feel it is important to do as much coding as possible. When you have to code to a deadline it is right nice to know that someone else did some of the work for you already though. That all said.... when I was a wee lad all excited because my aunt showed me a few commands on my parents BBC Micro I spent several days writing a way to perform a a set number of times. I was so proud of it and wanted to show it off. When I did I was shocked when told about this "FOR...NEXT" thing did the same blasted thing!
Sure, it's good to use other tools, but there's nothing wrong with writing your own thing, is there?
No, there's nothing wrong with it. Especially when your learning to program I feel it is important to do as much coding as possible.
I also think it's good to learn how it's done, at least the first time. I prefer to hand write the lexer/scanner part, rather than use strtok, as strtok is not flexible enough sometimes.