[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

File Classes

Posted on 2000-01-29
5
Medium Priority
?
142 Views
Last Modified: 2013-11-20
char *pszFileName2="C:\\My Documents\\mfc.txt";
CFile myFile3;
                        
if(!myFile3.Open(pszFileName2,CFile::modeRead))
{
     MessageBox("Unable To Open");
     return;
}

myFile3.Read(pbuf3,100);

lstrcpy(pbuf3,"0");
 
myFile3.Close();
                                        
if(lstrlen(pbuf3) != 0)
{
            char *pszFileName3="C:\\My    
        Documents\\mfc.txt";
            CFile myFile4;                  
                                    
            if(!myFile4.Open
        (pszFileName3,CFile::modeWrite))
            {
             MessageBox("Unable To
             Open1");
           return;      
            }
            myFile4.Write(pbuf3,100);         
}  



The following code above will read the contents of the file into a variable and then modification will be taken place on the variable before it is written back to the file.


The problem that i am facing is in the modification of the contents of the file. When i use the lstrcpy function it will copy the value 0 into the variable. After that using that value it will be written in the file. The problem now is the contents of the file.
It is not 0 alone in the file instead the first character will be 0 and the other character still remains there.


For instance the file has a value 400.
When i write the value 0 into the file it will look like this :

0 0

Regards

Eugene
0
Comment
Question by:eugene007
  • 3
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
Wyn earned 40 total points
ID: 2430201
Why dont you simple write zero to that file?
Btw:you can use
ZeroMemory() to make lbuf to zero.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2430241
Btw,would you please tell what's your purpose?It sounds strange.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2430341
opps,ignore my nonsense,it's "0" not 0x00:)
0
 

Author Comment

by:eugene007
ID: 2430562
char p[10]="i";
ZeroMemory(p,'0');
AfxMessageBox(p);

Problem :

When the contents of the variable p is displayed a illegal dialog box is displayed. How do i solve this problem.


Regards

Eugene
0
 

Author Comment

by:eugene007
ID: 2430941
Hi pal i manage to solve the problem already...thanks so much for helping me.

Regards

Eugene
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

612 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