Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: C Parsing

  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    C Parsing

    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.

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Would there be only one $ in a string or could there be multiple?
    OracleGuy

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    What code have you written so far?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #4
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oracleguy View Post
    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.)

  • #5
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    You could use regular expressions to easily pull matches out of a string.
    OracleGuy

  • #6
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oracleguy View Post
    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!

  • #7
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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/...pressions.html
    OracleGuy

  • #8
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #9
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Why not use '$' as the token to search for?
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •