Problem with CFile::Close 
Author Message
 Problem with CFile::Close

I am having a problem closing my files
It is probably that i don't know the commands correctly
i am using CFile
and the command

ftsFile.Close();
and it likes that but whenever i run the program it crashes after
 MessageBox("got this far2"); this message which is at the very end
and if OnOK(); is included it crashes after the window is closed
the code is below and what it does is
open two files one read one write, moves past the header info
then reads two hex bytes, flips them, then writes to the new file in
text
and closes
If any body sees the problem that would be great
Thanks Todd

unsigned int swap1,swap2;
 unsigned int data1[1],data3;
 char* ftsFileName = "f:\\1.fts";
 char* bldFileName = "f:\\1.bld";
 char* todd;
 CFile ftsFile, bldFile;
 if ( !ftsFile.Open(ftsFileName, CFile::modeRead), NULL)
 {
  MessageBox("File Doesn't Exist");  //check out open::Cfile for error
stuff
 }
 else
 {
  MessageBox("got this far1");
  bldFile.Open(bldFileName, CFile::modeCreate | CFile::modeWrite);
  ftsFile.Seek(2880L, CFile::begin);

   for (int count1=0;count1<=519;count1++)
   {
    for (int count2=0;count2<=782;count2++)
    {
     ftsFile.Read(data1,2);
     data3=*data1;
     swap1=data3/0x100;
     if (swap1==0x0a)
      {swap1=0x0b;}
     swap2=(unsigned int)fmod(data3,((data3/0x100)*0x100))*0x100;
     if (swap2==0x0a)
      {swap2=0x0b;}
     //fprintf(streamout,"%u ",storage[0][count2]);
     _ui64toa(swap1+swap2, todd, 16);
     //todd=storage[count2];
     bldFile.Write(todd,sizeof(todd));
    }
   bldFile.Write("\n",sizeof("\n"));
   }

  //ftsFile.Close();
  //bldFile.Close();
  //myFile.Close();  /should close but doesn't work
 }
 MessageBox("got this far2");
 OnOK();

Quote:
}



Wed, 22 Aug 2001 03:00:00 GMT  
 Problem with CFile::Close

Quote:

> I am having a problem closing my files
> It is probably that i don't know the commands correctly
> i am using CFile
> and the command

> ftsFile.Close();
> and it likes that but whenever i run the program it crashes after
>  MessageBox("got this far2"); this message which is at the very end
> and if OnOK(); is included it crashes after the window is closed
> the code is below and what it does is
> open two files one read one write, moves past the header info
> then reads two hex bytes, flips them, then writes to the new file in
> text
> and closes
> If any body sees the problem that would be great
> Thanks Todd

> unsigned int swap1,swap2;
>  unsigned int data1[1],data3;
>  char* ftsFileName = "f:\\1.fts";
>  char* bldFileName = "f:\\1.bld";
>  char* todd;
>  CFile ftsFile, bldFile;
>  if ( !ftsFile.Open(ftsFileName, CFile::modeRead), NULL)
>  {
>   MessageBox("File Doesn't Exist");  //check out open::Cfile for error
> stuff
>  }
>  else
>  {
>   MessageBox("got this far1");
>   bldFile.Open(bldFileName, CFile::modeCreate | CFile::modeWrite);
>   ftsFile.Seek(2880L, CFile::begin);

>    for (int count1=0;count1<=519;count1++)
>    {
>     for (int count2=0;count2<=782;count2++)
>     {
>      ftsFile.Read(data1,2);
>      data3=*data1;
>      swap1=data3/0x100;
>      if (swap1==0x0a)
>       {swap1=0x0b;}
>      swap2=(unsigned int)fmod(data3,((data3/0x100)*0x100))*0x100;
>      if (swap2==0x0a)
>       {swap2=0x0b;}
>      //fprintf(streamout,"%u ",storage[0][count2]);
>      _ui64toa(swap1+swap2, todd, 16);
>      //todd=storage[count2];
>      bldFile.Write(todd,sizeof(todd));
>     }
>    bldFile.Write("\n",sizeof("\n"));
>    }

>   //ftsFile.Close();
>   //bldFile.Close();
>   //myFile.Close();  /should close but doesn't work
>  }
>  MessageBox("got this far2");
>  OnOK();
> }

In
        _ui64toa(swap1+swap2, todd, 16);
Where have you allocated space for todd? It looks like you're
overwriting the stack. Try
        todd = new char[64];
Dont' forget to
        delete todd;
when you're done, so you don't have memory leaks.

PS Is there a shortage of .'s in Texas?



Wed, 22 Aug 2001 03:00:00 GMT  
 Problem with CFile::Close
Thanks
That worked great
except now i have another problem
i was trying to convert the hexidecimal to a text file
with number not hex
and thats what this line wa supposed to do
_ui64toa(swap1+swap2, todd, 16);
I just saw something that Cfile doesn't allow text
is this true
laters
todd


Wed, 22 Aug 2001 03:00:00 GMT  
 Problem with CFile::Close
Forget it
I am going to use fprintf
it works
laters
Todd


Wed, 22 Aug 2001 03:00:00 GMT  
 Problem with CFile::Close
don't forget to delete[] todd not delete todd.  Probably assumed, but delete
will still leave the memory out there.  :-)
Quote:


>> I am having a problem closing my files
>> It is probably that i don't know the commands correctly
>> i am using CFile
>> and the command

>> ftsFile.Close();
>> and it likes that but whenever i run the program it crashes after
>>  MessageBox("got this far2"); this message which is at the very end
>> and if OnOK(); is included it crashes after the window is closed
>> the code is below and what it does is
>> open two files one read one write, moves past the header info
>> then reads two hex bytes, flips them, then writes to the new file in
>> text
>> and closes
>> If any body sees the problem that would be great
>> Thanks Todd

>> unsigned int swap1,swap2;
>>  unsigned int data1[1],data3;
>>  char* ftsFileName = "f:\\1.fts";
>>  char* bldFileName = "f:\\1.bld";
>>  char* todd;
>>  CFile ftsFile, bldFile;
>>  if ( !ftsFile.Open(ftsFileName, CFile::modeRead), NULL)
>>  {
>>   MessageBox("File Doesn't Exist");  //check out open::Cfile for error
>> stuff
>>  }
>>  else
>>  {
>>   MessageBox("got this far1");
>>   bldFile.Open(bldFileName, CFile::modeCreate | CFile::modeWrite);
>>   ftsFile.Seek(2880L, CFile::begin);

>>    for (int count1=0;count1<=519;count1++)
>>    {
>>     for (int count2=0;count2<=782;count2++)
>>     {
>>      ftsFile.Read(data1,2);
>>      data3=*data1;
>>      swap1=data3/0x100;
>>      if (swap1==0x0a)
>>       {swap1=0x0b;}
>>      swap2=(unsigned int)fmod(data3,((data3/0x100)*0x100))*0x100;
>>      if (swap2==0x0a)
>>       {swap2=0x0b;}
>>      //fprintf(streamout,"%u ",storage[0][count2]);
>>      _ui64toa(swap1+swap2, todd, 16);
>>      //todd=storage[count2];
>>      bldFile.Write(todd,sizeof(todd));
>>     }
>>    bldFile.Write("\n",sizeof("\n"));
>>    }

>>   //ftsFile.Close();
>>   //bldFile.Close();
>>   //myFile.Close();  /should close but doesn't work
>>  }
>>  MessageBox("got this far2");
>>  OnOK();
>> }

>In
> _ui64toa(swap1+swap2, todd, 16);
>Where have you allocated space for todd? It looks like you're
>overwriting the stack. Try
> todd = new char[64];
>Dont' forget to
> delete todd;
>when you're done, so you don't have memory leaks.

>PS Is there a shortage of .'s in Texas?



Fri, 24 Aug 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Opening and closing a file on a Novell network using CFile

2. CFile file closing

3. Let me Know when to use CFile::Close();

4. CFile::Open asserts on CFile::typeText

5. CFile::Seek and CFile::Read over the network

6. Are CFile::Read() and CFile::Write() Really Unbuffered?

7. Millenium Read File problems (CFile)!

8. CFile Problem?

9. A problem on loading file using CFile

10. Use of CFile Class Problem

11. Problem with CFile and appending -- Help!

12. CFile problem ...

 

 
Powered by phpBB® Forum Software