nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

How to read configuration file line by line in C ?

This is a discussion on How to read configuration file line by line in C ? within the Coding in General forums, part of the Development/Scripting category; I'm in Linux Box (fedora) I have my config file : myfile.conf Code: scriptPath=/opt/myscript DBserver=localhost DBuser=me DBpassword=#123^abc# how can I ...


Go Back   nixCraft Linux Forum > Development/Scripting > Coding in General

Linux answers from nixCraft.


Coding in General Discussion on PHP/Perl/Python/Ruby/GNU C or C++. MySQL, PgSQL and (X)HTML or any other programming languages you want.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-22-2009, 10:22 PM
Junior Member
User
 
Join Date: Apr 2008
OS: Fedora 8
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 0
demuytree is on a distinguished road
Default How to read configuration file line by line in C ?

I'm in Linux Box (fedora)
I have my config file : myfile.conf
Code:
scriptPath=/opt/myscript
DBserver=localhost
DBuser=me
DBpassword=#123^abc#
how can I read this file line by line
and store its line to variable
to use in the C application !
Reply With Quote
  #2 (permalink)  
Old 06-26-2009, 09:00 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,697
Thanks: 11
Thanked 243 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

One approach is to read whole file in a loop and than use C function to read field while using = as deliminator.

Another option is to use C/C++ ini-parser http://student.agh.edu.pl/~koshmaar/SDL_Config/news.php
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply

Tags
c programming , gcc , gnu , ini parse , linux read ini files


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Script to open and read a file that is supplied as a command line arg blingbling Shell scripting 3 03-31-2009 10:54 AM
Shell script to count number of lines in file specified by the second command-line seaman77 Shell scripting 1 03-16-2009 07:46 PM
How to add new line using sed vprajeesh Mail Servers 0 03-03-2009 09:22 PM
HPUX Unix comparing 2 large files line by line raj HP-UX 1 02-11-2008 05:20 PM
Omit the first line in a file c341 Shell scripting 4 12-29-2006 02:07 PM


All times are GMT +5.5. The time now is 09:18 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2009 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38