Q: how best to use INI style files

From: Jim Backus (jhb_at_nospam.co.uk)
Date: 06/08/04


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


Relevant Pages

  • scalar MVT
    ... like this, a "usual" MVT exists, but not for vector-valued functions? ... equals the "secant line" at z? ...
    (sci.math)
  • Re: ? on math symbols
    ... >> equals sign with three lines instead of two, ... >> equals sign with a dot above and below, ... this all makes sense with the context they were used in I suppose. ... calculations, and all the things that can go wrong or make your calculations ...
    (sci.engr)