C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 1st, 2003, 12:40 AM
ZeRO ZeRO is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 64 ZeRO User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Make a c++ program w/ config files ?

How would I go about doing this ? I dont think #include would work, as it would build it in at compile time. I need it to open a file and check the variables there everytime the program is run. The config file would be like

namesrv1 = "ns1.sitename.com"; // Comment
namesrv2 = "ns2.sitename.com"; // Comment
ipaddr = "68.60.32.457"; // Comment

I need the C++ program to open it and translate this into std::string variables which can be used in the program. Any help would be appriciated.

Reply With Quote
  #2  
Old July 1st, 2003, 01:02 AM
TechNoFear TechNoFear is offline
Offensive Member
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2002
Location: in the perfect world
Posts: 594 TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 14 h 6 m 15 sec
Reputation Power: 21
I do this for my comercial apps....

Use special characters to find what the settings are. Assemble the data to a structure.

ie
[ and ] for group headings start and end
= for the break between a value and a its identifier

[IP_ADD]
host=127.168.0.1

[EOF]//marks end of file

strstr() will help.

roughly
Find the file size,
alloc mem for the file,
read whole file,
close file,
set char pointer to begining of buffer,
read config file settings to struct,
free file buffer memory
__________________
The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

Frank Zappa

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Make a c++ program w/ config files ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT