...

View Full Version : C Parsing



CM_2020
07-05-2008, 06:57 PM
So, here's what I'm wondering if you guys can help me with: I'm fairly new to coding C and I might just be missing a function, so if so this should be easy.

Here's the problem, or, at least, what I need my program to do.
User enters a string, optionally containing a symbol. So, like, "$." I need my program to parse out the string that directly follows it (excluding whitespace) and store it in a char.

So, if "user" entered "hello, my name is $bob what is yours?", the program would return "bob" to a character.

If this post is redundant, I apologize- I looked and didn't find anything similar.

I would greatly appreciate any help. :)

oracleguy
07-05-2008, 07:42 PM
Would there be only one $ in a string or could there be multiple?

Spookster
07-05-2008, 08:21 PM
What code have you written so far?

CM_2020
07-07-2008, 12:46 AM
Would there be only one $ in a string or could there be multiple?

There could be multiple. "Hello, my name is $bob and ^what is !your name" should pull out "bob," "what," and "your." (Obviously, as long as those three symbols were specified. It couldn't work with any symbol.)

oracleguy
07-07-2008, 12:55 AM
You could use regular expressions to easily pull matches out of a string.

CM_2020
07-07-2008, 11:30 PM
You could use regular expressions to easily pull matches out of a string.

This may sound very newbish, but how does one use regular expressions in C?

I know a fair amount of C, and I am a regexp wiz, but I don't know how to use them to parse out strings. @_@

Addendum: and didn't find much helpful literature on the subject. If anyone could either explain or point me in the direction of a nice resource, I would be indebted for eternity!

oracleguy
07-08-2008, 07:14 AM
You'll have to download and use a library to get regex support. You can google around and see what you can find. I found this quickly that might be of use: http://www.gnu.org/software/libtool/manual/libc/Regular-Expressions.html

CM_2020
07-08-2008, 08:48 AM
Okay.... I think I may have something here, and I was wondering if you guys could help me a little further? What my newest idea is was to use strtok() to split up input into a series of tokens using the ' ' character. Sooo... "hello, my name is $bob what is yours" would be split up into each of the individual words. However, in what way can I later search each individual token for the "$" character?

oracleguy
07-08-2008, 03:07 PM
Why not use '$' as the token to search for?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum