We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,956 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How Do i Parse???

Dudearoo
Useing Code::Blocks
How do i Parse??? Can you guys Teach me how to parse a Config File? i Do have the Boost Librarys Installed so if any of you have a way to do Parsing with it then thats ok, I will be able to Follow :)

Here is The Config File Named Settings

Settings.Config---------------------------------------------

TXTFont=16px
BKCLR=Black
Username=Dudearoo
// As A Comment

Settings.Config-----------------------------------------End

I want to Be able To Parse This Config File and load its values to strings, For Example
TXTFont(String) -> Text_DIVFontSize(String)
I've been useing File I/O For Quit a long time Now, and i still do not Know how to Parse! Please Help you guys :)

Ps. Oh by the way Please Dont send me of on some link so i can figure out how to do this on some other site, i want to you guys to teach me how(But of course Refrences IF Needed). :)

5
Contributors
8
Replies
1 Week
Discussion Span
7 Months Ago
Last Updated
9
Views
Dudearoo
Junior Poster in Training
53 posts since May 2012
Reputation Points: -3
Solved Threads: 0
Skill Endorsements: 0

Well I know you want someone here to teach you but I dont see the point if there are perfectly good lessons somewhere else. http://www.cplusplus.com/faq/sequences/strings/split/ has a very good tutorial on how to accomplish what you need. I would suggest try using what is there and see what you come up with. If youy still need help post the code you have, any errors you are getting and/or what it should be doing and what it is not doing and you should get some help.

NathanOliver
Posting Virtuoso
1,515 posts since Apr 2009
Reputation Points: 281
Solved Threads: 277
Skill Endorsements: 3

Look at the patterns. Each parameter in the config file has an '=' sign in it. The part before the '=' is the parameter, and the part after is the parameter value. So, do this.

  1. Read line into buffer.
  2. Check for comment character ('#')
  3. if no comment, look for '=' using strchr(buffer, '=')
  4. if return value from strchr is not null, you now know you have a parameter + value.

I leave the bit about extracting the parameter+value up to you. I only help with school problems - I don't solve them for you!

rubberman
Posting Maven
2,571 posts since Mar 2010
Reputation Points: 365
Solved Threads: 305
Skill Endorsements: 52

Um, first ill go to rubberman, i want my buffer to be a String(Sorry I should have said something :)) so i dont have to worry about the possable Character Length, possabley if you can show me a diffrent way for 3.? The other two i've got(Comment Read).
Second, NathanOliver Maybe if you could Explain In more Detail the way of the "Split The String", and Why i need to know this.

Plus: This IS NOT for Any Schooling of any type, I've tought my self All i know About C++.
Just if you were wondering :)

Dudearoo
Junior Poster in Training
53 posts since May 2012
Reputation Points: -3
Solved Threads: 0
Skill Endorsements: 0

Look up the methods in the string class. The methods for searching, splitting, and all that stuff are well documented.

WaltP
Posting Sage w/ dash of thyme
Team Colleague
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37

Can you tell me more detailed places to go? The Answers are great in all but i just want to know WHY I NEED TO KNOW this. :)

Dudearoo
Junior Poster in Training
53 posts since May 2012
Reputation Points: -3
Solved Threads: 0
Skill Endorsements: 0
WaltP
Posting Sage w/ dash of thyme
Team Colleague
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37

Can somebody Tell me another Way then strchr, Due to useing Chars, NOT C++ String, i cant use them for what i want. Thanks,

Dudearoo
Junior Poster in Training
53 posts since May 2012
Reputation Points: -3
Solved Threads: 0
Skill Endorsements: 0

Since you mentioned Boost, have you looked at Boost program_options? It has a nice syntax for parseing these kind of files. Lots of the tutorials on the site are about using it to parse command line arguments, but the is a section about parsing config file here.

The only thing that I think could be an issue is that you specified that // was to be used for comments, but program_options uses # by default. I don't know if that's configurable though.

Have fun

ravenous
Practically a Master Poster
681 posts since Jul 2005
Reputation Points: 286
Solved Threads: 111
Skill Endorsements: 9

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0894 seconds using 2.67MB