Link to home
Start Free TrialLog in
Avatar of andy06
andy06Flag for Germany

asked on

Saving array values with CFileDialog

Hi Experts,
I have a MFC dialog (VS2008 pro) application which includes a button to save  values.
By clicking on the button I should create a file (.txt) and save the array values (double) in it.This
.txt file should be used by another program for ploting.
This is what I'm trying to do:

void CTestDlg::OnBnClickedSaveValues()
{
 CFileDialog MyDialog ( FALSE, _T("txt"),NULL, OFN_HIDEREADONLY |OFN_CREATEPROMPT,_T ("Text Files(*.txt)|*.txt|"));
 CString TheString;
MyDialog.DoModal();
TheString = MyDialog.GetPathName();
FILE  *MyFile;
int  P=3, Loop=0;
double  a_old[3]={2.584,3.259,4.423},a[3],delta_a[3]={-0.142,0.0054,0.5};
double  Alpha=-0.658403, Rho=-0.2;      
//Open the file
MyFile= fopen(TheString,_T("a+"));
while(Loop<3)
{
      for(int j=0;j<P;j++)
            {
      a[j]=a_old[j] + Rho*Alpha*delta_a[j];
      //Here are the values of the array to be saved
      if( MyDialog.DoModal() == IDOK )
        {  
             fprintf(MyFile, "Loop %d\n", Loop);
              fprintf(MyFile, "%.7f\n", a[j]);
        }
              }
        Loop++;
}
    fclose(MyFile);      
}
And here is the error message:

error C2664: 'fopen' : cannot convert parameter 1 from 'CString' to 'const char *'

Andy
 
ASKER CERTIFIED SOLUTION
Avatar of alb66
alb66
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ps.
Should       if( MyDialog.DoModal() == IDOK )  really be inside the loop ?
Avatar of andy06

ASKER

>Change the project's character set from "unicode" to "multibyte"
Is there another option as to change the character set from "unicode" to "multibyte"?
>Should     if( MyDialog.DoModal() == IDOK )  really be inside the loop ?
No...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>Is there another option as to change the character set from "unicode" to "multibyte"?
As I suggested use the MFC supplied 'FILE' wrapper classes - they cope with UNICODE file names.


>Should     if( MyDialog.DoModal() == IDOK )  really be inside the loop ?  No...
:-)  Thought it looked odd.