Reading a file with CFile::Read 
Author Message
 Reading a file with CFile::Read

Hi,

I want to read a binary file into the memory, than access it.
When reading the file (i use CFile::Read ) i have to suply a buffer where to
put the data. The problem is that I don't know the size of the file thus i
can't provide the declaration of BUFFER with a maximum of size like char
BUFFER[10000].
Is there a solution to declare BUFFER with just the size of the file?

Hamid.



Sun, 06 Jan 2002 03:00:00 GMT  
 Reading a file with CFile::Read
CFile has a function GetStatus that has the ability to get the file size.
Also the Win32 API has a GetFileSize API.  A quick search of the online help
would have given you these answers.  I suggest you try looking there before
posting here.

- Anti_Snoop
http://www.snoopsoft.com


Quote:
> Hi,

> I want to read a binary file into the memory, than access it.
> When reading the file (i use CFile::Read ) i have to suply a buffer where
to
> put the data. The problem is that I don't know the size of the file thus i
> can't provide the declaration of BUFFER with a maximum of size like char
> BUFFER[10000].
> Is there a solution to declare BUFFER with just the size of the file?

> Hamid.



Sun, 06 Jan 2002 03:00:00 GMT  
 Reading a file with CFile::Read

Quote:
>I want to read a binary file into the memory, than access it.
>When reading the file (i use CFile::Read ) i have to suply a buffer where to
>put the data. The problem is that I don't know the size of the file thus i
>can't provide the declaration of BUFFER with a maximum of size like char
>BUFFER[10000].
>Is there a solution to declare BUFFER with just the size of the file?

Hamid,

Within reasonable memory allocation limits, you can use SeekToEnd to
determine the size of your file, and allocate the buffer to be the
same size as the file.

Dave
----
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Thu, 10 Jan 2002 03:00:00 GMT  
 Reading a file with CFile::Read
CFile f;
DWORD length = f.GetLength( );
LPBYTE buffer = new BYTE[length];

f.Read(buffer, length);
// ... do your thing here
delete buffer;


Quote:
> >I want to read a binary file into the memory, than access it.
> >When reading the file (i use CFile::Read ) i have to suply a buffer where
to
> >put the data. The problem is that I don't know the size of the file thus
i
> >can't provide the declaration of BUFFER with a maximum of size like char
> >BUFFER[10000].
> >Is there a solution to declare BUFFER with just the size of the file?

> Hamid,

> Within reasonable memory allocation limits, you can use SeekToEnd to
> determine the size of your file, and allocate the buffer to be the
> same size as the file.

> Dave
> ----
> My address is altered to discourage junk mail.
> Please post responses to the newsgroup thread,
> there's no need for follow-up email copies.



Fri, 11 Jan 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Reading ASCII float values with CFile.Read?

2. Does CFile:Read() block on a read?

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

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

5. CFile can't read file's update lie in novell

6. Millenium Read File problems (CFile)!

7. Reading from text files using CFile object

8. CFile Help please: reading data from file

9. CFile problem --- reading junk characters at the end of an file

10. CFile - question about reading file

11. Reading a File's contents using CFile

12. Reading a File's contents using CFile

 

 
Powered by phpBB® Forum Software