File Classes

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
eugene007Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WynCommented:
Why dont you simple write zero to that file?
Btw:you can use
ZeroMemory() to make lbuf to zero.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WynCommented:
Btw,would you please tell what's your purpose?It sounds strange.
0
WynCommented:
opps,ignore my nonsense,it's "0" not 0x00:)
0
eugene007Author Commented:
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
eugene007Author Commented:
Hi pal i manage to solve the problem already...thanks so much for helping me.

Regards

Eugene
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.