Solved

i just want to read info. *.ini file.

Posted on 2000-04-27
7
328 Views
Last Modified: 2010-04-02
if i have a code
wsprintf(szName,"f:\\amginl\\amginl%s.bmp",csc);
      DBChart1->SaveToBitmapFile(szName);
.
but now i want to write the path "f:\\amginl\\"in test.ini file.
and auto load the test.ini file to do
like a first code.how will i do ?
i think the code mabe is:
fopen("test.ini:);
...........
.........
wsprintf(szName,"%samginl%s.bmp",aaa,csc);
      DBChart1->SaveToBitmapFile(szName);
please tell me how will i do?

                        thanks.
0
Comment
Question by:tewehuang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 5

Expert Comment

by:proskig
ID: 2754560
Like this:
GetPrivateProfileString("Your Section in INI file","Bitmap file" , "", szBuffer, MAX_PATH, test.ini);

After it szBuffer contains value for a key "Bitmap file" under section "Your section in INI file". You might want to check registry functions documentation (e.g. in MSDN)
0
 
LVL 3

Accepted Solution

by:
abusimbel earned 110 total points
ID: 2754582
Hi...
Actually I think your problem is the way for
reading a file. Not for reading just an INI file
, isn't it?

If you want to use stdio functions (fprintf or
fscanf) you need to open the file, read what you
need with fscanf and use later. An example:

////
#include <stdio.h>


void main( void )
{
   FILE *fp;
   char szPath[255];

//you need to open the file...
//the "r" is the mode (read)...
   fp = fopen( "test.ini", "r" );

   if( file == NULL )
         printf( "Error opening the file." );
   else
   {
      //now you can read from the file like with scanf.
      //another possibilities are use fseek, fget,

      fscanf( fp, "%s", szPath );

      //you need to parse de INI file searching... the correct section and value.
      //...      
      // and then you have the value in szPath.      
      
      //use szPath on your way...

      //close the file.
      fclose(fp);      

   }
}


I suggest you read the help of those functions...
Another easier and C++ like way for reading a file
is using the iostream libs... It's easier if you
are familiar with the use of << and >> operators,
and so on...

Good luck...
0
 
LVL 3

Expert Comment

by:abusimbel
ID: 2754595
Really proskig is right... That's the easier way to read an INI file...

100 pts. to proskig :-)

But you ask for fopen, isn't it?
;-)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tewehuang
ID: 2754608
i just try to writed som code to go.
my source code is:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include "Unit1.h"
FILE *file1;
FILE *file2;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{

 while(!Query1->Eof)
  {
     
      file1 = fopen("c:\\amginl.ini","r");
      file2 = fopen("c:\\amgins.ini","r");
      String aaa,bbb ;
      fscanf(file1,"%s",aaa);
      fscanf(file2,"%s",bbb);
      char szName[255];
      // get data from first table
      // and save data into csc
      String csc = Query1->FindField("STKCODE")->AsString;
      String mkt = Query1->FindField("MKT")->AsString;
      // into csc to second table and get data

      if(mkt == "TSE"){
      Query2->Close();

      Query2->SQL->Clear();
      Query2->SQL->Add("select stkcode,syear*100+smon,sb_vol,lb_vol,cp");
      Query2->SQL->Add("from ap.amgin");
      Query2->SQL->Add("where STKCODE =:sss");
      Query2->ParamByName("sss")->AsString= csc;
      Query2->Active=TRUE;

     // use the data of second table to draw the line chart
      Series1->DataSource=Query2;
      Series1->ParentChart=DBChart1;
      Series1->XLabelsSource="syear*100+smon";
      Series1->YValues->ValueSource= "lb_vol";
      Series2->DataSource=Query2;
      Series2->ParentChart=DBChart2;
      Series2->XLabelsSource="syear*100+smon";
      Series2->YValues->ValueSource= "cp";
      wsprintf(szName,"%s\\amginl%s.bmp",aaa,csc);
      DBChart1->SaveToBitmapFile(szName);
      Series3->DataSource=Query2;
      Series3->ParentChart=DBChart2;
      Series3->XLabelsSource="syear*100+smon";
      Series3->YValues->ValueSource= "sb_vol";
      Series4->DataSource=Query2;
      Series4->ParentChart=DBChart1;
      Series4->XLabelsSource="syear*100+smon";
      Series4->YValues->ValueSource= "cp";
      wsprintf(szName,"%s\\agmgins%s.bmp",bbb,csc);
      DBChart2->SaveToBitmapFile(szName);
      Query1->Next();
      }
but i get some error message.
the message is:
access violation at address 3245c386 in module 'cp3245mt.dll".write of address 00000000
0
 

Author Comment

by:tewehuang
ID: 2754619
Adjusted points from 80 to 110
0
 

Author Comment

by:tewehuang
ID: 2754620
ok...sorry.i don't know the "ini" value.
so.i update the points.
but i just try the solution.
but get some trouble.
do you know what's happen?
0
 

Author Comment

by:tewehuang
ID: 2754642
ok...sorry.i don't know the "ini" value.
so.i update the points.
but i just try the solution.
but get some trouble.
do you know what's happen?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Building cUrl in Windows v7.43.0 4 39
GUI: DIalog Stacking and Popping in MS C++ 4 87
C++ question 3 74
find Speed using GPS latitude & longitude 4 83
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question