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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing to files

Status
Not open for further replies.

ferryjenny

Technical User
Nov 22, 2000
24
0
0
GB
I am trying to write the contents of an edit box to a txt file however it is not working. When the dialog is first opened the edit box contains some text and the user then changes this text. I have written the code below to write the text in the edit box to a file.

FILE* fp;

if((fp = fopen("file.txt","w"))==NULL)
{
AfxMessageBox("the file was not opened");
exit(0);
}

fputs(_editbox,fp);

However this only writes the text that was in the edit box initially and not the new text that the user has entered. Thanks for any help received.
 
Add a command button (e.g.OK) to the form and add a callback when the user presses the command button. Do your file io then.
 
This is what I have done however it is not working.
 
> However this only writes the text that was in the edit box initially
> and not the new text that the user has entered.

> fputs(_editbox,fp);

If the variable '_editbox' is a CString that is mapped to the edit control using MFC DDX then you need to do this at the top of the function:

UpdateData();

That transfers the current contents of the edit window into the CString variable.

Hope this helps
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top