*.INI Files

40da7e74fdca33768b6714646853b3f5
0
TheLionKing 101 Oct 01, 2003 at 09:39

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

23 Replies

Please log in or register to post a reply.

22b3033832c5c699c856814b0cf80cb1
0
bladder 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.

40da7e74fdca33768b6714646853b3f5
0
TheLionKing 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: !

22b3033832c5c699c856814b0cf80cb1
0
bladder 101 Oct 01, 2003 at 15:15

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 );
F7a4a748ecf664f189bb704a660b3573
0
anubis 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…

6ad5f8c742f1e8ec61000e2b0900fc76
0
davepermen 101 Oct 01, 2003 at 16:24

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

F7a4a748ecf664f189bb704a660b3573
0
anubis 101 Oct 01, 2003 at 19:04

:lol: :lol: :lol:

40da7e74fdca33768b6714646853b3f5
0
TheLionKing 101 Oct 02, 2003 at 03:10

Sorry I ask :confused: !

6ad5f8c742f1e8ec61000e2b0900fc76
0
davepermen 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..

F7a4a748ecf664f189bb704a660b3573
0
anubis 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.

6ae9e55570b3974db134b46f1752c925
0
cjp88can 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).

6ad5f8c742f1e8ec61000e2b0900fc76
0
davepermen 101 Sep 01, 2004 at 07:48

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

6ae9e55570b3974db134b46f1752c925
0
cjp88can 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.

F7a4a748ecf664f189bb704a660b3573
0
anubis 101 Sep 01, 2004 at 12:44

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

6ad5f8c742f1e8ec61000e2b0900fc76
0
davepermen 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

6ae9e55570b3974db134b46f1752c925
0
cjp88can 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:

7543b5c50738e23b200e69fe697ea85a
0
NomadRock 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…

F7a4a748ecf664f189bb704a660b3573
0
anubis 101 Sep 01, 2004 at 16:18

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

7543b5c50738e23b200e69fe697ea85a
0
NomadRock 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.

F7a4a748ecf664f189bb704a660b3573
0
anubis 101 Sep 01, 2004 at 17:50

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

0684f9d33f52fa189aad7ac9e8c87510
0
baldurk 101 Sep 01, 2004 at 19:04

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

7543b5c50738e23b200e69fe697ea85a
0
NomadRock 101 Sep 02, 2004 at 02:34

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

48d5487f357fbcacc89e84720577f0ac
0
Steven_Hansen 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?

6ad5f8c742f1e8ec61000e2b0900fc76
0
davepermen 101 Sep 06, 2004 at 06:40

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)