Jump to content
  • Advertisement
Sign in to follow this  
azherdev

[C++] Parsing INI file loaded as char*

This topic is 4214 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can anyone help me find a library to parse char* that contains the contents of an INI file? I retrieve the file from a ZIP file and it comes out as void*.

Share this post


Link to post
Share on other sites
Advertisement
I'll be surprised if such a thing exists - why not just write it yourself? The ini format is incredibly straightforwards, it shouldn't take more than a couple of hours to get working.

What language? C? C++? C#?

Share this post


Link to post
Share on other sites
It seems simple, but getting all those error trappings takes time and I'm still very amatuerish in the realm of strings, character pointers, etc.

Anyhoo, I already found one that is perfect for what I need, it loads it from a file or from a string. If anyone is interested: http://code.jellycan.com/.

I've done INI parsing in .NET before, but it was so much easier with string classes and streams. C++ is kicking my butt for now so I need as much help as I can get. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by azherdev
I've done INI parsing in .NET before, but it was so much easier with string classes and streams. C++ is kicking my butt for now so I need as much help as I can get. :)

Who says C++ doesn't have those things? std::string is more than adequate for strings, and <iostream> and <fstream> should do more than enough for reading files, inserting, and extracting. This is a good guide for using file streams. If you're curious as to the actual implementation of such a constructed parser, I'm sure someone can dig something up.

-jouley

Share this post


Link to post
Share on other sites
Oh, I have no doubt C++ has abundant supply of string manipulation. I am just new to it. I mean, you are talking to a guy who is still getting over the fact that I can't do this:



char *string;

string = "Hello World " + "This is cool";



And I do use std::string versus char* whenever I can. I'm just not so comfortable with it yet.

Share this post


Link to post
Share on other sites
Quote:
Original post by azherdev
Oh, I have no doubt C++ has abundant supply of string manipulation. I am just new to it. I mean, you are talking to a guy who is still getting over the fact that I can't do this:



char *string;

string = "Hello World " + "This is cool";



And I do use std::string versus char* whenever I can. I'm just not so comfortable with it yet.


You can actually do that with string.

#include <string>

using namespace std;

string s;
s = "Hello World" + "Whatever";
or

s = "Hello ";
s += "World ";
s += " Whatever";

The string class methods will make it a lot easier to parse the ini file, than a char array. Because you have to be careful with the char array, and make sure you don't read over the bounds and stuff like that... just load the whole file into a string, and use the functions substr() and find().

Share this post


Link to post
Share on other sites
Quote:
Original post by azherdev
Oh, I have no doubt C++ has abundant supply of string manipulation. I am just new to it. I mean, you are talking to a guy who is still getting over the fact that I can't do this:



char *string;

string = "Hello World " + "This is cool";



And I do use std::string versus char* whenever I can. I'm just not so comfortable with it yet.

Comfort comes with practice, and the more practice you have not using char*'s, the better off you'll be. [smile] All those troubles you alluded to earlier could easily be bypassed with std::string. For example, to modify your example slightly:
std::string strTemp;
strTmp = "Hello World";
strTmp += ", This is cool!";

std::string strFull = strTmp + " And so is std::string!";

Nearly everything you expect to be able to do you can, with much more safety and less trouble than char's. It's not a bad idea to learn about them, but using std::strings is just easier.

In the end, though, do what works!
-jouley

[Edit: Bojangled! But by good advice, so s'cool.]

Share this post


Link to post
Share on other sites
Dude, I have so much to learn, so little time. :) Thank you guys. Looks like strings will save me. I'm now reading up on them.

... I love C++ support... ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by Vampyre_Dark
#include <string>

using namespace std;

string s;
s = "Hello World" + "Whatever";
Actually, this would not work. You are still adding two literal strings. You could do
s = s + "Hello World" + "Whatever";
or
s = string("Hello World") + "Whatever";
or
s = string()+"Hello World" + "Whatever";

or, the C way:
s = "Hello World" "Whatever";

Share this post


Link to post
Share on other sites
Quote:
Original post by Vampyre_Dark
You can actually do that with string.

#include <string>

using namespace std;

string s;
s = "Hello World" + "Whatever";
Not so - That'll give you an error saying you can't add two pointers.

You can however, do this:
s = std::string("Hello World") + "Whatever";
Or:
s = "Hello World" + std::string("Whatever");
Or:
s = std::string("Hello World") + std::string("Whatever");


EDIT: Bah, too slow

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!