my program has two edit control boxes that display text from a text file, and they both have buttons associated with them that update the text files associated with them if anything is written or deleted in the edit control boxes. i have this code to read from a text file
try
{
CStdioFile file(_T("1.txt"), CFile::modeRead);
CString str,mainstr = _T("");
while(file.ReadString(str))
{
mainstr += str;
mainstr += _T("\r\n");
}
CWnd *editwindow = this->GetDlgItem(IDC_EDIT2);
editwindow->SetWindowText(mainstr);
}
catch(CException* e)
{
MessageBox(_T("no such file"));
e->Delete();
}
and then this code to write to the text file
m_addtext.GetWindowText(m_adtxt);
if ( IsDlgButtonChecked(IDC_RADIO1) == BST_CHECKED )
{
CStdioFile file;
file.Open (_T("1.txt"), CFile::modeCreate | CFile::modeWrite);
file.WriteString (m_adtxt);
file.Close ();
}
it all works pretty much fine and dandy for what i want, but the problem is is that it adds a block character after a word if i delete a character in the edit box, and then click the update button. sometimes it even adds a block after every word and one block on every empty line. it works fine as long as it creates a new file and nothing is deleted. i've tried null terminating, i've tried ccs="encoding"
. can anyone point me in the right direction?