Create, Read, Write to INI file in C

margarit
margarit used Ask the Experts™
on
Hello,

I am using C (on linux).
Is there any way to access INI files in C (not in C# or C++)? I need to create , read and write INI files.
If yes, can you please give me an example or link to commands?

THANKS
Margarit
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
evilrixSenior Software Engineer (Avast)

Commented:
This appears to be an open source library capable of reading INI files.
http://sourceforge.net/projects/libini

INI Parser Library: An INI file parser that can read, edit and create large INI files. Usable under Microsoft Windows, DOS, Linux, etc
masheikSoftware Engineer

Commented:
oh .. evilrix already posted my apologies..
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

evilrixSenior Software Engineer (Avast)

Commented:
No worries :)

Author

Commented:
Thanks a lot!
But is there any built in functions/libraries to work with INI files or XML files in C?
 Thanks
 
evilrixSenior Software Engineer (Avast)

Commented:
>> But is there any built in functions/libraries to work with INI files or XML files in C?
Short answer... no.

Author

Commented:
I need to save parameters values in some file (using C in linux). What is the easiest way to do it? I thought of INI files because they have sections and keys.
THANKS
masheikSoftware Engineer

Commented:
There is no ancii c support for ini files..or xml
evilrixSenior Software Engineer (Avast)

Commented:
>> I need to save parameters values in some file (using C in linux). What is the easiest way to do it?

You need to define your own format, C has no support for anything along those lines. If you were using C++ I could recommend Boost program options.

http://www.boost.org/doc/libs/1_39_0/doc/html/program_options.html

Author

Commented:
I am using simple C :(
evilrixSenior Software Engineer (Avast)

Commented:
>> I am using simple C :(
Yeah... the important word there is "simple" :)
Yes need to use GetPrivateProfileString () and WritePrivateProfileString ().
http://msdn.microsoft.com/en-us/library/ms724353(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms725501(VS.85).aspx
U can use the example given there for ur understanding...
evilrixSenior Software Engineer (Avast)

Commented:
>> Yes need to use GetPrivateProfileString () and WritePrivateProfileString ().
Subrat2009, the question starts, "I am using C (on linux)." :)

Author

Commented:
evilirix:
Hello again,
I think I should ask you about the INI parser in this question.
http://sourceforge.net/projects/libini
How should I use this parser. I should save the file inside my project folder and include in my project?
Thanks
 
 
Senior Software Engineer (Avast)
Commented:
>> How should I use this parser. I should save the file inside my project folder and include in my project?

It's a standard Linux tarball. Did you try reading the instructions of installation and usage that come with the package? They are pretty clear.

<INSTALL>
The simplest way to compile this package is:

  1. `cd' to the directory containing the package's source code and type
     `./configure' to configure the package for your system.  If you're
     using `csh' on an old version of System V, you might need to type
     `sh ./configure' instead to prevent `csh' from trying to execute
     `configure' itself.

     Running `configure' takes a while.  While running, it prints some
     messages telling which features it is checking for.

  2. Type `make' to compile the package.

  3. Type `make install' to install the programs and any data files and
     documentation.

  4. You can remove the program binaries and object files from the
     source code directory by typing `make clean'.  
</INSTALL>

It's a library that you need to build and then link your project against.


Author

Commented:
Hello,
evilrix:
THANKS a lot. I first opened the folder on windows so did not see the intallation instructions. But now I opened it on linux and saw all the files inside. I succeded to configure and compile it!  So now I hope my life will be easier :)
masheik:
I tried the link you gave me and after a bit  of trying I succeded running the code from this link. It seems to work OK except one small problem I am trying to solve.
THANKS AGAIN
 

Author

Commented:
Thanks for patience
masheikSoftware Engineer

Commented:
you are welcome...
evilrixSenior Software Engineer (Avast)

Commented:
>> THANKS AGAIN
No worries... have fun :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial