By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

CEdit Problem

100+
P: 100
HI,
I have an MFC code which has a dialog and a menu.One menu option is Edit which has "Copy File content".There are 2 CEdit boxs.IDC_EDIT2 and IDC_EDIT3.I am reading the text in the Edit boxes.

My code builds properly but while running it gives me an exception

It is actually getting into the if statement
Expand|Select|Wrap|Line Numbers
  1. if (!Inputfile.Open(str, nOpenFlags, &FileExc)) {
  2.     FileExc.ReportError();
  3.     return;
  4.     }
  5.  
My full code is....

Expand|Select|Wrap|Line Numbers
  1. afx_msg void CExoDialog::OnGamma()
  2. {
  3.     CEdit *edit1=(CEdit*)GetDlgItem(IDC_EDIT2);
  4.  
  5.     char str[80],str1[80];
  6.     int i,j;
  7.     i=edit1->GetWindowText(str,sizeof(str-1));
  8.  
  9.     CEdit *edit2=(CEdit*)GetDlgItem(IDC_EDIT3);
  10.     j=edit2->GetWindowText(str1,sizeof(str1-1));
  11.  
  12.     CStdioFile Inputfile, Outputfile;
  13.     CFileException FileExc;
  14.     UINT nOpenFlags;
  15.     CString s;
  16. nOpenFlags = CFile::modeRead;
  17. if (!Inputfile.Open(str, nOpenFlags, &FileExc)) {
  18.     FileExc.ReportError();
  19.     return;
  20.     }
  21. nOpenFlags = CFile::modeWrite | CFile::modeCreate;
  22. if (!Outputfile.Open(str1, nOpenFlags, &FileExc)) {
  23.     FileExc.ReportError();
  24.     return;
  25.     }
  26. while (Inputfile.ReadString(s))
  27.     Outputfile.WriteString(s);
  28.  
  29. Inputfile.Close();
  30. Outputfile.Close();
  31.  
Jun 20 '07 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
if (!Inputfile.Open(str, nOpenFlags, &FileExc)) {
FileExc.ReportError();
return;
}
Shouldn't that be str1 instead of str?
Jun 20 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.