Q: how best to use INI style files
From: Jim Backus (jhb_at_nospam.co.uk)
Date: 06/08/04
- Next message: Elliot Marks: "[C] please critique my code"
- Previous message: Edo: "Re: parsing text"
- Next in thread: Thomas Matthews: "Re: Q: how best to use INI style files"
- Reply: Thomas Matthews: "Re: Q: how best to use INI style files"
- Reply: Kapt. Boogschutter: "Re: how best to use INI style files"
- Reply: Niklas Borson: "Re: Q: how best to use INI style files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 8 Jun 2004 21:19:14 +0000 (UTC)
I'm planning to convert a program written in Rexx to C as an exercise
while learning C.
One thing I want to do is to have a configuration file similar to .ini
files to set a number of variables.
A typical ini file has a structure with a section name enclosed in
square brackets followed by a number of variables with values. For
example the Windows system.ini can have a section like this:
[vcache]
minvcache=1024
maxvcache=8192
My question is: what is the best or recommended way of doing this in
C?
I've thought of two ways:
1. Read in a line and parse it so that the part before the equals sign
is a variable name and the part after the equals sign is the
variable's value.
2. Declare all possible variables in the C program and parse the "ini"
file setting any variables found to the value after the equals sign.
My gut feeling is that (2) is the best way. Any variables used in the
program will need to be known anyway. Using (1) could result in a
mistyped variable name setting a value that the program wouldn't
recognise whereas (2) would ignore a misspelling.
Suggestions and advice please - I'm a complete newbie to C so you are
unlikely to offend :-)
TIA
Jim
-- Jim Backus OS/2 user since 1994 bona fide replies to j <dot> backus <the circle thingy> jita <dot> demon <dot> co <dot> uk
- Next message: Elliot Marks: "[C] please critique my code"
- Previous message: Edo: "Re: parsing text"
- Next in thread: Thomas Matthews: "Re: Q: how best to use INI style files"
- Reply: Thomas Matthews: "Re: Q: how best to use INI style files"
- Reply: Kapt. Boogschutter: "Re: how best to use INI style files"
- Reply: Niklas Borson: "Re: Q: how best to use INI style files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|