LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 08-16-2005, 12:21 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,028

Rep: Reputation: 45
read parameters from a file (c language)


Hi i need an example or a program (so as to read the code) in order to understand how i can read parameters from a file (something like /etc/smb.conf)
Have a nice day
 
Old 08-16-2005, 02:12 AM   #2
Philelec
LQ Newbie
 
Registered: Sep 2004
Posts: 5

Rep: Reputation: 0
search Google, you will find a lot of tutorials and examples of how to open a file with C prog.
 
Old 08-16-2005, 02:43 AM   #3
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,028

Original Poster
Rep: Reputation: 45
I have tried that but no good results...
 
Old 08-16-2005, 03:07 AM   #4
Philelec
LQ Newbie
 
Registered: Sep 2004
Posts: 5

Rep: Reputation: 0
I could give you some examples of routine, but has they are "home made", they would probably be not undersandablefor someone who don't know how to use it ...

Serch about "fopen" and "fread".

The basis is that you have to :
open the file using fopen. (with option read/write..., type of file suc binary or text)
read it to memory, using a routine, using fread.
close the file after use.

Once the file is transfered into memory, you need to extract the data interesting yourself.

It's not really difficult... once you have founded how to do.

I don't know how deep you are aware in C programming, but it's like all read/write of datas (pipes, sockets,...)

The best I could suggest you, if you don't find it using Google, is to buy a serious book of system programming. They all talk about this subject. I could give you a very good reference but it's french.

Let's know.
 
Old 08-16-2005, 03:13 AM   #5
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,282

Rep: Reputation: 61
Also man strtok may help to parse config with delimited fields
 
Old 08-16-2005, 05:50 AM   #6
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,028

Original Poster
Rep: Reputation: 45
Thx a lot guys..give me also that reference
 
Old 08-16-2005, 01:29 PM   #7
Philelec
LQ Newbie
 
Registered: Sep 2004
Posts: 5

Rep: Reputation: 0
a lot to learn ...


http://www.eyrolles.com/Informatique/Livre/9782212116014/livre-programmation-systeme-en-c-sous-linux.php


and learning french together. !

a little bit hard to understand for start, but fully usefull for learning file handling, pipes, and so..

Good luck.
 
Old 08-20-2005, 08:57 AM   #8
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,028

Original Poster
Rep: Reputation: 45
Thx for the link ... but i dont have the money to afford it... If u can help me a little more e.x provide me some sample code if u have some so i can undestrand how i can parse parameters from a file
the file will have the following format
parameter1=value1
parameter2=value2
parameter3=value3
so i need some generic functions for parsing parameters as well the values... If u dont have the time plz suggest me how to start... thx a lot
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH: read every line in the files and use the line as parameters as another program tam3c36 Programming 10 12-07-2010 01:42 PM
Read parameters from config file (file parser?) alaios Programming 6 09-12-2005 12:39 AM
use file content as tcl script parameters powah Linux - General 3 07-16-2005 11:10 AM
how do I make a read-only file NOT read-only? robster Linux - General 1 02-17-2004 09:11 PM
Change from Read only to Read Write File System? justiceisblind Linux - Newbie 3 03-03-2002 07:23 PM


All times are GMT -5. The time now is 05:08 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration