Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read INI file 1

Status
Not open for further replies.

jamescpp

IS-IT--Management
Aug 29, 2001
70
US
I have a program that current takes args from the command line. Instead, I would like to have these stored in an INI file and read when the program starts.

Can anyone help, especially maybe a pointer to some example code? Please don't just point me to tutorials unless they are specific to this. I've tried that route and it's information overload, couldn't find what I was looking for.

Any help is appreciated.
James
 
#include<fstream>
#include<string>
using namespaces std;
int main()
{
char buf[100];
other variables...;
ifstream your_inifile(&quot;name_of_file.ini&quot;);
your_inifile>>buf;
if(string(buf) == srting(&quot;some_variable_name&quot;)
{
your_inifile.getline(buf,100);
//or .2 your_inifile>>somevariable;

sscanf(buf,&quot;%...&quot;,&variable);
//interpreting of buf, if .2 then sscanf not required
}
return 0;
} Ion Filipski
1c.bmp


filipski@excite.com
 
Guess I'm not in the right forum. When I try to include #include<fstream> and #include<string> I get an error: fatal error C1189: #error : &quot;eh.h is only for C++!&quot;

How do I do this in a C program, not C++.

Sorry, I'm not much of a c/c++ programmer. Just had this program dropped in my lap and need to make some changes to it.

If anyone in this forum can still help I'd appreciate it.

Thanks,
James
 
are you using .C or .CPP files? Be attentive. Ion Filipski
1c.bmp


filipski@excite.com
 
in this case you'll be able to use only C functions. Use cpp files. Ion Filipski
1c.bmp


filipski@excite.com
 
I appreciate your effort. Sorry for the mistake.
 
don't sorry, just go on. Thsi forums is 60% for fixing bugs and mistakes Ion Filipski
1c.bmp


filipski@excite.com
 
Is this running on Windoze or some other OS? Seeing as this is a &quot;C++: Microsoft&quot; forum, this is rather pertinent.

Windows has built in MFC code for reading .ini files.

See GetPrivateProfileString() in the MSDN.

If you are not doing this for windows, I'd suggest you pick another forum and you will likely get more help.

Regards,

Charles
 
Hi Charles,
it is not a java forum and question is not for java. By the way, even the code I put there is in C++ it is compatible with all C++ compillers. Ion Filipski
1c.bmp


filipski@excite.com
 
By the way, Charles, have you ever seen other OS than windows? You write there windoze as you're the best unix user in the world. Ion Filipski
1c.bmp


filipski@excite.com
 
What the hell is your point Ion? Did my post suggest that I THOUGHT this was a Java question?

Believe it or not, I am fluent in more languages than just Java. In fact, I have been rebuilding an MFC app these last few weeks and have learned quite a few MFC calls, including dealing with .ini files.

GetPrivateProfileString() is an MFC call that allows you to retrieve .ini entries.

Although you have misinterpreted my post to the contrary, I am suggesting that, rather than reinventing the wheel, he use the existing win32 api or MFC code if he is in fact writing his app for Windows.
 
I'm not sure what your major malfunction is Ion but I hope you seek some help.

Although I am an experienced Unix user, I'm not sure how you got from point A to point B. Are you just looking to pick a fight?
 
I don't want to get in the middle of a battle here, but let me answer the inquiry. Yes the program is for windows. I am interested in using built in API's, so I will look into that. For now it is working based on Ion's suggestion in the c forum.

Thanks.
James
 
I think you wasn't careful. If you think I didn't know what did you write, you're wrong. You can see thread207-121751 with a similar question. But this is a question for C language by mistake posted in C++ forum, see thread205-129208.
About Unix, I don't like when someone try to what he is someone in something by using crouching words. For example I like Windows2000, even I use both, LinuxMandrake8 and Windows2000 Server. For me windoze sounds Ion Filipski
1c.bmp


filipski@excite.com
 
At the end I wanted to write sounds at least a little strange. Ion Filipski
1c.bmp


filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top