0
101 Oct 01, 2003 at 09:39

How do we use the *.INI files. I mean to read and write to them ?

#### 23 Replies

0
101 Oct 01, 2003 at 14:05

Just as you would any other file.

Either use ofstream and ifstream or do it the C way, ie: FILE* fread/fwrite. Nothing special about them. They’re mostly just text files anyway.

0
101 Oct 01, 2003 at 15:00

I knwo how to open other files … but it has spaces and braces [] ? I just know to read and write a structure or some variables to the files without any spaces :blush: !

0
101 Oct 01, 2003 at 15:15

FILE* fp = fopen( "file.ini", "r" );

char c;

while( c = fread( &c, 1, 1, fp ) )
{
if( c == ' ' )
cout<< "A space! A space! w00000t"<< endl;

}


writing to ini files

FILE* fp = fopen( "file.ini", "a+" );

char someText[256];

strcpy( someText, "text with spaces" );

fwrite( someText, 1, strlen(someText)+1, fp );

0
101 Oct 01, 2003 at 15:45

i know i just made a post about respect for other people but this is basic knowledge… get a book on c/c++ and use the msdn library. don’t you think that this is something you could have figured out yourself ? i don’t mind you asking but i doubt the learning effect for yourself. think about it…

0
101 Oct 01, 2003 at 16:24

hehe, your limit of respect is lower than my one it seems. but not by much:D

0
101 Oct 01, 2003 at 19:04

:lol: :lol: :lol:

0
101 Oct 02, 2003 at 03:10

0
101 Oct 02, 2003 at 09:27

don’t look into the world that sad!

oh, and, yes, there is, in the win32 api, a special api to manipulate .ini files actually. never used it myself, though..

0
101 Oct 02, 2003 at 11:18

no don’t be sorry… as i said i don’t mind you asking at all. i’m even glad to answer any question you have (as i hopefully did in the past ). it’s just that i think that you can learn a lot more when playing around with your code until it works. especially when it is basic stuff like reading an parsing text from a file.

0
101 Sep 01, 2004 at 07:44

Here’s a tip don’t bother with ini for game data unless you really need to. Look what happend to some of the Command & Conqour games from ini files. (Mod making).

0
101 Sep 01, 2004 at 07:48

necromancy? well.. anyways, yeah, today, xml is way to go :D

0
101 Sep 01, 2004 at 07:55

Yea xml would be a lot better I guess. One more thing TheLionKing if you ever make an online game down the road and use ini files to state levels and such of a player or whatever it is, don’t have it with a client lol so many people do that and then think how people got their stats so high. So if you use ini run it with the server and let the client read and write data through it.

0
101 Sep 01, 2004 at 12:44

yeah… posting in stone age threads !!!
hey dave i got xml serialization over the network working yesterday :)

0
101 Sep 01, 2004 at 12:57

great! i was playing a bit with rss - saving, and i am able now to do some sort of news-posting into xml directly. now i should handle it over net, too :D

0
101 Sep 01, 2004 at 15:24

@anubis

yeah… posting in stone age threads !!!
hey dave i got xml serialization over the network working yesterday :) [snapback]10130[/snapback]

Lock me up and throw away the key. :nervous:

0
101 Sep 01, 2004 at 15:29

Is there any way to lock old threads. This really got to be a problem in flipCode and could easily kill this site too…

0
101 Sep 01, 2004 at 16:18

yes there is… or do you mean autmatically ? maybe that can be implemented

0
101 Sep 01, 2004 at 16:35

Yes, I mean if a thread hasn’t been posted in for at least X months, then it is automatically locked.

0
101 Sep 01, 2004 at 17:50

that would be a good idea. i’m sure Dia can do this

0
101 Sep 01, 2004 at 19:04

What the.. ? Since when did everyone start agreeing that necromancy was a bad idea?

0
101 Sep 02, 2004 at 02:34

Its cool in movies and fantasy games, but it is always bad in real life.

0
101 Sep 05, 2004 at 21:53

@davepermen

oh, and, yes, there is, in the win32 api, a special api to manipulate .ini files actually. never used it myself, though.. [snapback]4989[/snapback]

Well, I wrote a bunch of ini stuff by hand a while back since my work specifically required it. An API would have been nicer/easier (perhaps), but I didn’t know that one existed. So… out of belated curiosity, under what name would a person look to find this api? (Please don’t specify search terms. Msdn searches are nightmares of complexity and always return 500+ matches that usually have to do with FoxPro which isn’t even installed on my system :angry:). Oh… and yeah I’m sure I could find it myself, but I prefer to ask annoying questions as opposed to looking through the annoying msdn database. :P

And too… I’m guessing that this was the intent of the OP’s question. Perhaps it should have been phrased, “Is there an API for writing to/reading from .ini files?” Additionally, he might have been asking if there were any particular conventions to adhere to when writing to .ini files. Anyone know?

0
101 Sep 06, 2004 at 06:40