PDA

View Full Version : *.INI Files


TheLionKing
10-01-2003, 03:39 AM
How do we use the *.INI files. I mean to read and write to them ?

bladder
10-01-2003, 08:05 AM
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.

TheLionKing
10-01-2003, 09:00 AM
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: !

bladder
10-01-2003, 09:15 AM
reading ini files


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 );

anubis
10-01-2003, 09:45 AM
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...

davepermen
10-01-2003, 10:24 AM
hehe, your limit of respect is lower than my one it seems. but not by much:D

anubis
10-01-2003, 01:04 PM
:lol: :lol: :lol:

TheLionKing
10-01-2003, 09:10 PM
Sorry I ask :confused: !

davepermen
10-02-2003, 03:27 AM
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..

anubis
10-02-2003, 05:18 AM
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.

cjp88can
09-01-2004, 01:44 AM
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).

davepermen
09-01-2004, 01:48 AM
necromancy? well.. anyways, yeah, today, xml is way to go :D

cjp88can
09-01-2004, 01:55 AM
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.

anubis
09-01-2004, 06:44 AM
yeah... posting in stone age threads !!!
hey dave i got xml serialization over the network working yesterday :)

davepermen
09-01-2004, 06:57 AM
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

cjp88can
09-01-2004, 09:24 AM
yeah... posting in stone age threads !!!
hey dave i got xml serialization over the network working yesterday :)
10130


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

NomadRock
09-01-2004, 09:29 AM
Is there any way to lock old threads. This really got to be a problem in flipCode and could easily kill this site too...

anubis
09-01-2004, 10:18 AM
yes there is... or do you mean autmatically ? maybe that can be implemented

NomadRock
09-01-2004, 10:35 AM
Yes, I mean if a thread hasn't been posted in for at least X months, then it is automatically locked.

anubis
09-01-2004, 11:50 AM
that would be a good idea. i'm sure Dia can do this

baldurk
09-01-2004, 01:04 PM
What the.. ? Since when did everyone start agreeing that necromancy was a bad idea?

NomadRock
09-01-2004, 08:34 PM
Its cool in movies and fantasy games, but it is always bad in real life.

Steven Hansen
09-05-2004, 03:53 PM
oh, and, yes, there is, in the win32 api, a special api to manipulate .ini files actually. never used it myself, though..
4989


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?

davepermen
09-06-2004, 12:40 AM
just use google on msdn..
search in google like this "MSDN WhatEverIWant" to get it. most the time.

i don't know much about the ini-stuff anymore, as i dropped support for it long ago. i played around with a lot of own fileformats afterwards, and now i'm 100% xml.. (while i still don't like it, it's just the most easy way to do :D)